diff --git a/ApiKeys/samples/V2/ApiKeysClient/create_key.php b/ApiKeys/samples/V2/ApiKeysClient/create_key.php index aab6931b3429..f3eaf59347bb 100644 --- a/ApiKeys/samples/V2/ApiKeysClient/create_key.php +++ b/ApiKeys/samples/V2/ApiKeysClient/create_key.php @@ -25,7 +25,8 @@ // [START apikeys_v2_generated_ApiKeys_CreateKey_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\ApiKeys\V2\ApiKeysClient; +use Google\Cloud\ApiKeys\V2\Client\ApiKeysClient; +use Google\Cloud\ApiKeys\V2\CreateKeyRequest; use Google\Cloud\ApiKeys\V2\Key; use Google\Rpc\Status; @@ -43,13 +44,16 @@ function create_key_sample(string $formattedParent): void // Create a client. $apiKeysClient = new ApiKeysClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $key = new Key(); + $request = (new CreateKeyRequest()) + ->setParent($formattedParent) + ->setKey($key); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $apiKeysClient->createKey($formattedParent, $key); + $response = $apiKeysClient->createKey($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/ApiKeys/samples/V2/ApiKeysClient/delete_key.php b/ApiKeys/samples/V2/ApiKeysClient/delete_key.php index 82da4a8766ac..ad85e4fa17de 100644 --- a/ApiKeys/samples/V2/ApiKeysClient/delete_key.php +++ b/ApiKeys/samples/V2/ApiKeysClient/delete_key.php @@ -25,7 +25,8 @@ // [START apikeys_v2_generated_ApiKeys_DeleteKey_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\ApiKeys\V2\ApiKeysClient; +use Google\Cloud\ApiKeys\V2\Client\ApiKeysClient; +use Google\Cloud\ApiKeys\V2\DeleteKeyRequest; use Google\Cloud\ApiKeys\V2\Key; use Google\Rpc\Status; @@ -44,10 +45,14 @@ function delete_key_sample(string $formattedName): void // Create a client. $apiKeysClient = new ApiKeysClient(); + // Prepare the request message. + $request = (new DeleteKeyRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $apiKeysClient->deleteKey($formattedName); + $response = $apiKeysClient->deleteKey($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/ApiKeys/samples/V2/ApiKeysClient/get_key.php b/ApiKeys/samples/V2/ApiKeysClient/get_key.php index 5e4651e8c8ea..2233d3702980 100644 --- a/ApiKeys/samples/V2/ApiKeysClient/get_key.php +++ b/ApiKeys/samples/V2/ApiKeysClient/get_key.php @@ -24,7 +24,8 @@ // [START apikeys_v2_generated_ApiKeys_GetKey_sync] use Google\ApiCore\ApiException; -use Google\Cloud\ApiKeys\V2\ApiKeysClient; +use Google\Cloud\ApiKeys\V2\Client\ApiKeysClient; +use Google\Cloud\ApiKeys\V2\GetKeyRequest; use Google\Cloud\ApiKeys\V2\Key; /** @@ -42,10 +43,14 @@ function get_key_sample(string $formattedName): void // Create a client. $apiKeysClient = new ApiKeysClient(); + // Prepare the request message. + $request = (new GetKeyRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var Key $response */ - $response = $apiKeysClient->getKey($formattedName); + $response = $apiKeysClient->getKey($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ApiKeys/samples/V2/ApiKeysClient/get_key_string.php b/ApiKeys/samples/V2/ApiKeysClient/get_key_string.php index 62dd7a442431..5d6c27306ee5 100644 --- a/ApiKeys/samples/V2/ApiKeysClient/get_key_string.php +++ b/ApiKeys/samples/V2/ApiKeysClient/get_key_string.php @@ -24,7 +24,8 @@ // [START apikeys_v2_generated_ApiKeys_GetKeyString_sync] use Google\ApiCore\ApiException; -use Google\Cloud\ApiKeys\V2\ApiKeysClient; +use Google\Cloud\ApiKeys\V2\Client\ApiKeysClient; +use Google\Cloud\ApiKeys\V2\GetKeyStringRequest; use Google\Cloud\ApiKeys\V2\GetKeyStringResponse; /** @@ -41,10 +42,14 @@ function get_key_string_sample(string $formattedName): void // Create a client. $apiKeysClient = new ApiKeysClient(); + // Prepare the request message. + $request = (new GetKeyStringRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var GetKeyStringResponse $response */ - $response = $apiKeysClient->getKeyString($formattedName); + $response = $apiKeysClient->getKeyString($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ApiKeys/samples/V2/ApiKeysClient/list_keys.php b/ApiKeys/samples/V2/ApiKeysClient/list_keys.php index cb2ede054b80..14792e60cea3 100644 --- a/ApiKeys/samples/V2/ApiKeysClient/list_keys.php +++ b/ApiKeys/samples/V2/ApiKeysClient/list_keys.php @@ -25,8 +25,9 @@ // [START apikeys_v2_generated_ApiKeys_ListKeys_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; -use Google\Cloud\ApiKeys\V2\ApiKeysClient; +use Google\Cloud\ApiKeys\V2\Client\ApiKeysClient; use Google\Cloud\ApiKeys\V2\Key; +use Google\Cloud\ApiKeys\V2\ListKeysRequest; /** * Lists the API keys owned by a project. The key string of the API key @@ -43,10 +44,14 @@ function list_keys_sample(string $formattedParent): void // Create a client. $apiKeysClient = new ApiKeysClient(); + // Prepare the request message. + $request = (new ListKeysRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $apiKeysClient->listKeys($formattedParent); + $response = $apiKeysClient->listKeys($request); /** @var Key $element */ foreach ($response as $element) { diff --git a/ApiKeys/samples/V2/ApiKeysClient/lookup_key.php b/ApiKeys/samples/V2/ApiKeysClient/lookup_key.php index cc889c84a0d7..e530422fb16c 100644 --- a/ApiKeys/samples/V2/ApiKeysClient/lookup_key.php +++ b/ApiKeys/samples/V2/ApiKeysClient/lookup_key.php @@ -24,7 +24,8 @@ // [START apikeys_v2_generated_ApiKeys_LookupKey_sync] use Google\ApiCore\ApiException; -use Google\Cloud\ApiKeys\V2\ApiKeysClient; +use Google\Cloud\ApiKeys\V2\Client\ApiKeysClient; +use Google\Cloud\ApiKeys\V2\LookupKeyRequest; use Google\Cloud\ApiKeys\V2\LookupKeyResponse; /** @@ -41,10 +42,14 @@ function lookup_key_sample(string $keyString): void // Create a client. $apiKeysClient = new ApiKeysClient(); + // Prepare the request message. + $request = (new LookupKeyRequest()) + ->setKeyString($keyString); + // Call the API and handle any network failures. try { /** @var LookupKeyResponse $response */ - $response = $apiKeysClient->lookupKey($keyString); + $response = $apiKeysClient->lookupKey($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ApiKeys/samples/V2/ApiKeysClient/undelete_key.php b/ApiKeys/samples/V2/ApiKeysClient/undelete_key.php index ba80f216103d..5b463be37f61 100644 --- a/ApiKeys/samples/V2/ApiKeysClient/undelete_key.php +++ b/ApiKeys/samples/V2/ApiKeysClient/undelete_key.php @@ -25,8 +25,9 @@ // [START apikeys_v2_generated_ApiKeys_UndeleteKey_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\ApiKeys\V2\ApiKeysClient; +use Google\Cloud\ApiKeys\V2\Client\ApiKeysClient; use Google\Cloud\ApiKeys\V2\Key; +use Google\Cloud\ApiKeys\V2\UndeleteKeyRequest; use Google\Rpc\Status; /** @@ -43,10 +44,14 @@ function undelete_key_sample(string $formattedName): void // Create a client. $apiKeysClient = new ApiKeysClient(); + // Prepare the request message. + $request = (new UndeleteKeyRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $apiKeysClient->undeleteKey($formattedName); + $response = $apiKeysClient->undeleteKey($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/ApiKeys/samples/V2/ApiKeysClient/update_key.php b/ApiKeys/samples/V2/ApiKeysClient/update_key.php index a5824e522ae3..44c30c827b3b 100644 --- a/ApiKeys/samples/V2/ApiKeysClient/update_key.php +++ b/ApiKeys/samples/V2/ApiKeysClient/update_key.php @@ -25,8 +25,9 @@ // [START apikeys_v2_generated_ApiKeys_UpdateKey_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\ApiKeys\V2\ApiKeysClient; +use Google\Cloud\ApiKeys\V2\Client\ApiKeysClient; use Google\Cloud\ApiKeys\V2\Key; +use Google\Cloud\ApiKeys\V2\UpdateKeyRequest; use Google\Rpc\Status; /** @@ -47,13 +48,15 @@ function update_key_sample(): void // Create a client. $apiKeysClient = new ApiKeysClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $key = new Key(); + $request = (new UpdateKeyRequest()) + ->setKey($key); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $apiKeysClient->updateKey($key); + $response = $apiKeysClient->updateKey($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/ApiKeys/src/V2/Client/ApiKeysClient.php b/ApiKeys/src/V2/Client/ApiKeysClient.php new file mode 100644 index 000000000000..e5c96b4fdf93 --- /dev/null +++ b/ApiKeys/src/V2/Client/ApiKeysClient.php @@ -0,0 +1,40 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/api_keys_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/api_keys_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/api_keys_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/api_keys_rest_client_config.php', + ], + ], + ]; + } + + /** + * Return an OperationsClient object with the same endpoint as $this. + * + * @return OperationsClient + */ + public function getOperationsClient() + { + return $this->operationsClient; + } + + /** + * Resume an existing long running operation that was previously started by a long + * running API method. If $methodName is not provided, or does not match a long + * running API method, then the operation can still be resumed, but the + * OperationResponse object will not deserialize the final response. + * + * @param string $operationName The name of the long running operation + * @param string $methodName The name of the method used to start the operation + * + * @return OperationResponse + */ + public function resumeOperation($operationName, $methodName = null) + { + $options = isset($this->descriptors[$methodName]['longRunning']) ? $this->descriptors[$methodName]['longRunning'] : []; + $operation = new OperationResponse($operationName, $this->getOperationsClient(), $options); + $operation->reload(); + return $operation; + } + + /** + * Formats a string containing the fully-qualified path to represent a key + * resource. + * + * @param string $project + * @param string $location + * @param string $key + * + * @return string The formatted key resource. + */ + public static function keyName(string $project, string $location, string $key): string + { + return self::getPathTemplate('key')->render([ + 'project' => $project, + 'location' => $location, + 'key' => $key, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a location + * resource. + * + * @param string $project + * @param string $location + * + * @return string The formatted location resource. + */ + public static function locationName(string $project, string $location): string + { + return self::getPathTemplate('location')->render([ + 'project' => $project, + 'location' => $location, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * Template: Pattern + * - key: projects/{project}/locations/{location}/keys/{key} + * - location: projects/{project}/locations/{location} + * + * The optional $template argument can be supplied to specify a particular pattern, + * and must match one of the templates listed above. If no $template argument is + * provided, or if the $template argument does not match one of the templates + * listed, then parseName will check each of the supported templates, and return + * the first match. + * + * @param string $formattedName The formatted name string + * @param string $template Optional name of template to match + * + * @return array An associative array from name component IDs to component values. + * + * @throws ValidationException If $formattedName could not be matched. + */ + public static function parseName(string $formattedName, string $template = null): array + { + return self::parseFormattedName($formattedName, $template); + } + + /** + * Constructor. + * + * @param array $options { + * Optional. Options for configuring the service API wrapper. + * + * @type string $apiEndpoint + * The address of the API remote host. May optionally include the port, formatted + * as ":". Default 'apikeys.googleapis.com:443'. + * @type string|array|FetchAuthTokenInterface|CredentialsWrapper $credentials + * The credentials to be used by the client to authorize API calls. This option + * accepts either a path to a credentials file, or a decoded credentials file as a + * PHP array. + * *Advanced usage*: In addition, this option can also accept a pre-constructed + * {@see \Google\Auth\FetchAuthTokenInterface} object or + * {@see \Google\ApiCore\CredentialsWrapper} object. Note that when one of these + * objects are provided, any settings in $credentialsConfig will be ignored. + * @type array $credentialsConfig + * Options used to configure credentials, including auth token caching, for the + * client. For a full list of supporting configuration options, see + * {@see \Google\ApiCore\CredentialsWrapper::build()} . + * @type bool $disableRetries + * Determines whether or not retries defined by the client configuration should be + * disabled. Defaults to `false`. + * @type string|array $clientConfig + * Client method configuration, including retry settings. This option can be either + * a path to a JSON file, or a PHP array containing the decoded JSON data. By + * default this settings points to the default client config file, which is + * provided in the resources folder. + * @type string|TransportInterface $transport + * The transport used for executing network requests. May be either the string + * `rest` or `grpc`. Defaults to `grpc` if gRPC support is detected on the system. + * *Advanced usage*: Additionally, it is possible to pass in an already + * instantiated {@see \Google\ApiCore\Transport\TransportInterface} object. Note + * that when this object is provided, any settings in $transportConfig, and any + * $apiEndpoint setting, will be ignored. + * @type array $transportConfig + * Configuration options that will be used to construct the transport. Options for + * each supported transport type should be passed in a key for that transport. For + * example: + * $transportConfig = [ + * 'grpc' => [...], + * 'rest' => [...], + * ]; + * See the {@see \Google\ApiCore\Transport\GrpcTransport::build()} and + * {@see \Google\ApiCore\Transport\RestTransport::build()} methods for the + * supported options. + * @type callable $clientCertSource + * A callable which returns the client cert as a string. This can be used to + * provide a certificate and private key to the transport layer for mTLS. + * } + * + * @throws ValidationException + */ + public function __construct(array $options = []) + { + $clientOptions = $this->buildClientOptions($options); + $this->setClientOptions($clientOptions); + $this->operationsClient = $this->createOperationsClient($clientOptions); + } + + /** Handles execution of the async variants for each documented method. */ + public function __call($method, $args) + { + if (substr($method, -5) !== 'Async') { + trigger_error('Call to undefined method ' . __CLASS__ . "::$method()", E_USER_ERROR); + } + + array_unshift($args, substr($method, 0, -5)); + return call_user_func_array([$this, 'startAsyncCall'], $args); + } + + /** + * Creates a new API key. + * + * NOTE: Key is a global resource; hence the only supported value for + * location is `global`. + * + * The async variant is {@see self::createKeyAsync()} . + * + * @param CreateKeyRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function createKey(CreateKeyRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('CreateKey', $request, $callOptions)->wait(); + } + + /** + * Deletes an API key. Deleted key can be retrieved within 30 days of + * deletion. Afterward, key will be purged from the project. + * + * NOTE: Key is a global resource; hence the only supported value for + * location is `global`. + * + * The async variant is {@see self::deleteKeyAsync()} . + * + * @param DeleteKeyRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function deleteKey(DeleteKeyRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('DeleteKey', $request, $callOptions)->wait(); + } + + /** + * Gets the metadata for an API key. The key string of the API key + * isn't included in the response. + * + * NOTE: Key is a global resource; hence the only supported value for + * location is `global`. + * + * The async variant is {@see self::getKeyAsync()} . + * + * @param GetKeyRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Key + * + * @throws ApiException Thrown if the API call fails. + */ + public function getKey(GetKeyRequest $request, array $callOptions = []): Key + { + return $this->startApiCall('GetKey', $request, $callOptions)->wait(); + } + + /** + * Get the key string for an API key. + * + * NOTE: Key is a global resource; hence the only supported value for + * location is `global`. + * + * The async variant is {@see self::getKeyStringAsync()} . + * + * @param GetKeyStringRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return GetKeyStringResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function getKeyString(GetKeyStringRequest $request, array $callOptions = []): GetKeyStringResponse + { + return $this->startApiCall('GetKeyString', $request, $callOptions)->wait(); + } + + /** + * Lists the API keys owned by a project. The key string of the API key + * isn't included in the response. + * + * NOTE: Key is a global resource; hence the only supported value for + * location is `global`. + * + * The async variant is {@see self::listKeysAsync()} . + * + * @param ListKeysRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listKeys(ListKeysRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListKeys', $request, $callOptions); + } + + /** + * Find the parent project and resource name of the API + * key that matches the key string in the request. If the API key has been + * purged, resource name will not be set. + * The service account must have the `apikeys.keys.lookup` permission + * on the parent project. + * + * The async variant is {@see self::lookupKeyAsync()} . + * + * @param LookupKeyRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return LookupKeyResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function lookupKey(LookupKeyRequest $request, array $callOptions = []): LookupKeyResponse + { + return $this->startApiCall('LookupKey', $request, $callOptions)->wait(); + } + + /** + * Undeletes an API key which was deleted within 30 days. + * + * NOTE: Key is a global resource; hence the only supported value for + * location is `global`. + * + * The async variant is {@see self::undeleteKeyAsync()} . + * + * @param UndeleteKeyRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function undeleteKey(UndeleteKeyRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('UndeleteKey', $request, $callOptions)->wait(); + } + + /** + * Patches the modifiable fields of an API key. + * The key string of the API key isn't included in the response. + * + * NOTE: Key is a global resource; hence the only supported value for + * location is `global`. + * + * The async variant is {@see self::updateKeyAsync()} . + * + * @param UpdateKeyRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function updateKey(UpdateKeyRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('UpdateKey', $request, $callOptions)->wait(); + } +} diff --git a/ApiKeys/src/V2/CreateKeyRequest.php b/ApiKeys/src/V2/CreateKeyRequest.php index 88b615ddb481..e0c6b3efebae 100644 --- a/ApiKeys/src/V2/CreateKeyRequest.php +++ b/ApiKeys/src/V2/CreateKeyRequest.php @@ -42,6 +42,34 @@ class CreateKeyRequest extends \Google\Protobuf\Internal\Message */ private $key_id = ''; + /** + * @param string $parent Required. The project in which the API key is created. Please see + * {@see ApiKeysClient::locationName()} for help formatting this field. + * @param \Google\Cloud\ApiKeys\V2\Key $key Required. The API key fields to set at creation time. + * You can configure only the `display_name`, `restrictions`, and + * `annotations` fields. + * @param string $keyId User specified key id (optional). If specified, it will become the final + * component of the key resource name. + * + * The id must be unique within the project, must conform with RFC-1034, + * is restricted to lower-cased letters, and has a maximum length of 63 + * characters. In another word, the id must match the regular + * expression: `[a-z]([a-z0-9-]{0,61}[a-z0-9])?`. + * + * The id must NOT be a UUID-like string. + * + * @return \Google\Cloud\ApiKeys\V2\CreateKeyRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\ApiKeys\V2\Key $key, string $keyId): self + { + return (new self()) + ->setParent($parent) + ->setKey($key) + ->setKeyId($keyId); + } + /** * Constructor. * diff --git a/ApiKeys/src/V2/DeleteKeyRequest.php b/ApiKeys/src/V2/DeleteKeyRequest.php index d4c5a8fec0c6..ab2d74394d00 100644 --- a/ApiKeys/src/V2/DeleteKeyRequest.php +++ b/ApiKeys/src/V2/DeleteKeyRequest.php @@ -29,6 +29,20 @@ class DeleteKeyRequest extends \Google\Protobuf\Internal\Message */ private $etag = ''; + /** + * @param string $name Required. The resource name of the API key to be deleted. Please see + * {@see ApiKeysClient::keyName()} for help formatting this field. + * + * @return \Google\Cloud\ApiKeys\V2\DeleteKeyRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/ApiKeys/src/V2/GetKeyRequest.php b/ApiKeys/src/V2/GetKeyRequest.php index 3e7224678964..e9d137c7deaa 100644 --- a/ApiKeys/src/V2/GetKeyRequest.php +++ b/ApiKeys/src/V2/GetKeyRequest.php @@ -22,6 +22,20 @@ class GetKeyRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The resource name of the API key to get. Please see + * {@see ApiKeysClient::keyName()} for help formatting this field. + * + * @return \Google\Cloud\ApiKeys\V2\GetKeyRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/ApiKeys/src/V2/GetKeyStringRequest.php b/ApiKeys/src/V2/GetKeyStringRequest.php index 00f36e5e9a5e..9366e02c076f 100644 --- a/ApiKeys/src/V2/GetKeyStringRequest.php +++ b/ApiKeys/src/V2/GetKeyStringRequest.php @@ -22,6 +22,20 @@ class GetKeyStringRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The resource name of the API key to be retrieved. Please see + * {@see ApiKeysClient::keyName()} for help formatting this field. + * + * @return \Google\Cloud\ApiKeys\V2\GetKeyStringRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/ApiKeys/src/V2/ListKeysRequest.php b/ApiKeys/src/V2/ListKeysRequest.php index d13e7640604a..7f78cb01a8d6 100644 --- a/ApiKeys/src/V2/ListKeysRequest.php +++ b/ApiKeys/src/V2/ListKeysRequest.php @@ -41,6 +41,20 @@ class ListKeysRequest extends \Google\Protobuf\Internal\Message */ private $show_deleted = false; + /** + * @param string $parent Required. Lists all API keys associated with this project. Please see + * {@see ApiKeysClient::locationName()} for help formatting this field. + * + * @return \Google\Cloud\ApiKeys\V2\ListKeysRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/ApiKeys/src/V2/UpdateKeyRequest.php b/ApiKeys/src/V2/UpdateKeyRequest.php index 5c0dfcf80b0a..c3bf1a08d73a 100644 --- a/ApiKeys/src/V2/UpdateKeyRequest.php +++ b/ApiKeys/src/V2/UpdateKeyRequest.php @@ -36,6 +36,29 @@ class UpdateKeyRequest extends \Google\Protobuf\Internal\Message */ private $update_mask = null; + /** + * @param \Google\Cloud\ApiKeys\V2\Key $key Required. Set the `name` field to the resource name of the API key to be + * updated. You can update only the `display_name`, `restrictions`, and + * `annotations` fields. + * @param \Google\Protobuf\FieldMask $updateMask The field mask specifies which fields to be updated as part of this + * request. All other fields are ignored. + * Mutable fields are: `display_name`, `restrictions`, and `annotations`. + * If an update mask is not provided, the service treats it as an implied mask + * equivalent to all allowed fields that are set on the wire. If the field + * mask has a special value "*", the service treats it equivalent to replace + * all allowed mutable fields. + * + * @return \Google\Cloud\ApiKeys\V2\UpdateKeyRequest + * + * @experimental + */ + public static function build(\Google\Cloud\ApiKeys\V2\Key $key, \Google\Protobuf\FieldMask $updateMask): self + { + return (new self()) + ->setKey($key) + ->setUpdateMask($updateMask); + } + /** * Constructor. * diff --git a/ApiKeys/src/V2/resources/api_keys_descriptor_config.php b/ApiKeys/src/V2/resources/api_keys_descriptor_config.php index c83e3ac1e3fc..cfdbad576236 100644 --- a/ApiKeys/src/V2/resources/api_keys_descriptor_config.php +++ b/ApiKeys/src/V2/resources/api_keys_descriptor_config.php @@ -12,6 +12,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'DeleteKey' => [ 'longRunning' => [ @@ -22,6 +31,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'UndeleteKey' => [ 'longRunning' => [ @@ -32,6 +50,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'UpdateKey' => [ 'longRunning' => [ @@ -42,6 +69,40 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'key.name', + 'fieldAccessors' => [ + 'getKey', + 'getName', + ], + ], + ], + ], + 'GetKey' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\ApiKeys\V2\Key', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetKeyString' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\ApiKeys\V2\GetKeyStringResponse', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'ListKeys' => [ 'pageStreaming' => [ @@ -52,6 +113,24 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getKeys', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\ApiKeys\V2\ListKeysResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'LookupKey' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\ApiKeys\V2\LookupKeyResponse', + ], + 'templateMap' => [ + 'key' => 'projects/{project}/locations/{location}/keys/{key}', + 'location' => 'projects/{project}/locations/{location}', ], ], ], diff --git a/ApiKeys/tests/Unit/V2/Client/ApiKeysClientTest.php b/ApiKeys/tests/Unit/V2/Client/ApiKeysClientTest.php new file mode 100644 index 000000000000..aa7dd6cdcc82 --- /dev/null +++ b/ApiKeys/tests/Unit/V2/Client/ApiKeysClientTest.php @@ -0,0 +1,958 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return ApiKeysClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new ApiKeysClient($options); + } + + /** @test */ + public function createKeyTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/createKeyTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $uid = 'uid115792'; + $displayName = 'displayName1615086568'; + $keyString = 'keyString526755313'; + $etag = 'etag3123477'; + $expectedResponse = new Key(); + $expectedResponse->setName($name); + $expectedResponse->setUid($uid); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setKeyString($keyString); + $expectedResponse->setEtag($etag); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createKeyTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $key = new Key(); + $request = (new CreateKeyRequest()) + ->setParent($formattedParent) + ->setKey($key); + $response = $gapicClient->createKey($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.api.apikeys.v2.ApiKeys/CreateKey', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getKey(); + $this->assertProtobufEquals($key, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createKeyTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function createKeyExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/createKeyTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $key = new Key(); + $request = (new CreateKeyRequest()) + ->setParent($formattedParent) + ->setKey($key); + $response = $gapicClient->createKey($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createKeyTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function deleteKeyTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/deleteKeyTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name2 = 'name2-1052831874'; + $uid = 'uid115792'; + $displayName = 'displayName1615086568'; + $keyString = 'keyString526755313'; + $etag2 = 'etag2-1293302904'; + $expectedResponse = new Key(); + $expectedResponse->setName($name2); + $expectedResponse->setUid($uid); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setKeyString($keyString); + $expectedResponse->setEtag($etag2); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/deleteKeyTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->keyName('[PROJECT]', '[LOCATION]', '[KEY]'); + $request = (new DeleteKeyRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteKey($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.api.apikeys.v2.ApiKeys/DeleteKey', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteKeyTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function deleteKeyExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/deleteKeyTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->keyName('[PROJECT]', '[LOCATION]', '[KEY]'); + $request = (new DeleteKeyRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteKey($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteKeyTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function getKeyTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $uid = 'uid115792'; + $displayName = 'displayName1615086568'; + $keyString = 'keyString526755313'; + $etag = 'etag3123477'; + $expectedResponse = new Key(); + $expectedResponse->setName($name2); + $expectedResponse->setUid($uid); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setKeyString($keyString); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->keyName('[PROJECT]', '[LOCATION]', '[KEY]'); + $request = (new GetKeyRequest()) + ->setName($formattedName); + $response = $gapicClient->getKey($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.api.apikeys.v2.ApiKeys/GetKey', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getKeyExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->keyName('[PROJECT]', '[LOCATION]', '[KEY]'); + $request = (new GetKeyRequest()) + ->setName($formattedName); + try { + $gapicClient->getKey($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getKeyStringTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $keyString = 'keyString526755313'; + $expectedResponse = new GetKeyStringResponse(); + $expectedResponse->setKeyString($keyString); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->keyName('[PROJECT]', '[LOCATION]', '[KEY]'); + $request = (new GetKeyStringRequest()) + ->setName($formattedName); + $response = $gapicClient->getKeyString($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.api.apikeys.v2.ApiKeys/GetKeyString', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getKeyStringExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->keyName('[PROJECT]', '[LOCATION]', '[KEY]'); + $request = (new GetKeyStringRequest()) + ->setName($formattedName); + try { + $gapicClient->getKeyString($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listKeysTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $keysElement = new Key(); + $keys = [ + $keysElement, + ]; + $expectedResponse = new ListKeysResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setKeys($keys); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListKeysRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listKeys($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getKeys()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.api.apikeys.v2.ApiKeys/ListKeys', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listKeysExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListKeysRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listKeys($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function lookupKeyTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $parent = 'parent-995424086'; + $name = 'name3373707'; + $expectedResponse = new LookupKeyResponse(); + $expectedResponse->setParent($parent); + $expectedResponse->setName($name); + $transport->addResponse($expectedResponse); + // Mock request + $keyString = 'keyString526755313'; + $request = (new LookupKeyRequest()) + ->setKeyString($keyString); + $response = $gapicClient->lookupKey($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.api.apikeys.v2.ApiKeys/LookupKey', $actualFuncCall); + $actualValue = $actualRequestObject->getKeyString(); + $this->assertProtobufEquals($keyString, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function lookupKeyExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $keyString = 'keyString526755313'; + $request = (new LookupKeyRequest()) + ->setKeyString($keyString); + try { + $gapicClient->lookupKey($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function undeleteKeyTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/undeleteKeyTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name2 = 'name2-1052831874'; + $uid = 'uid115792'; + $displayName = 'displayName1615086568'; + $keyString = 'keyString526755313'; + $etag = 'etag3123477'; + $expectedResponse = new Key(); + $expectedResponse->setName($name2); + $expectedResponse->setUid($uid); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setKeyString($keyString); + $expectedResponse->setEtag($etag); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/undeleteKeyTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->keyName('[PROJECT]', '[LOCATION]', '[KEY]'); + $request = (new UndeleteKeyRequest()) + ->setName($formattedName); + $response = $gapicClient->undeleteKey($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.api.apikeys.v2.ApiKeys/UndeleteKey', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/undeleteKeyTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function undeleteKeyExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/undeleteKeyTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->keyName('[PROJECT]', '[LOCATION]', '[KEY]'); + $request = (new UndeleteKeyRequest()) + ->setName($formattedName); + $response = $gapicClient->undeleteKey($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/undeleteKeyTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function updateKeyTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/updateKeyTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $uid = 'uid115792'; + $displayName = 'displayName1615086568'; + $keyString = 'keyString526755313'; + $etag = 'etag3123477'; + $expectedResponse = new Key(); + $expectedResponse->setName($name); + $expectedResponse->setUid($uid); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setKeyString($keyString); + $expectedResponse->setEtag($etag); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/updateKeyTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $key = new Key(); + $request = (new UpdateKeyRequest()) + ->setKey($key); + $response = $gapicClient->updateKey($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.api.apikeys.v2.ApiKeys/UpdateKey', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getKey(); + $this->assertProtobufEquals($key, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateKeyTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function updateKeyExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/updateKeyTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $key = new Key(); + $request = (new UpdateKeyRequest()) + ->setKey($key); + $response = $gapicClient->updateKey($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateKeyTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function createKeyAsyncTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/createKeyTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $uid = 'uid115792'; + $displayName = 'displayName1615086568'; + $keyString = 'keyString526755313'; + $etag = 'etag3123477'; + $expectedResponse = new Key(); + $expectedResponse->setName($name); + $expectedResponse->setUid($uid); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setKeyString($keyString); + $expectedResponse->setEtag($etag); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createKeyTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $key = new Key(); + $request = (new CreateKeyRequest()) + ->setParent($formattedParent) + ->setKey($key); + $response = $gapicClient->createKeyAsync($request)->wait(); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.api.apikeys.v2.ApiKeys/CreateKey', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getKey(); + $this->assertProtobufEquals($key, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createKeyTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } +} diff --git a/ApigeeRegistry/samples/V1/ProvisioningClient/create_instance.php b/ApigeeRegistry/samples/V1/ProvisioningClient/create_instance.php index f81897ce4492..c8071bc30066 100644 --- a/ApigeeRegistry/samples/V1/ProvisioningClient/create_instance.php +++ b/ApigeeRegistry/samples/V1/ProvisioningClient/create_instance.php @@ -25,9 +25,10 @@ // [START apigeeregistry_v1_generated_Provisioning_CreateInstance_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\ApigeeRegistry\V1\Client\ProvisioningClient; +use Google\Cloud\ApigeeRegistry\V1\CreateInstanceRequest; use Google\Cloud\ApigeeRegistry\V1\Instance; use Google\Cloud\ApigeeRegistry\V1\Instance\Config; -use Google\Cloud\ApigeeRegistry\V1\ProvisioningClient; use Google\Rpc\Status; /** @@ -50,16 +51,20 @@ function create_instance_sample( // Create a client. $provisioningClient = new ProvisioningClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $instanceConfig = (new Config()) ->setCmekKeyName($instanceConfigCmekKeyName); $instance = (new Instance()) ->setConfig($instanceConfig); + $request = (new CreateInstanceRequest()) + ->setParent($formattedParent) + ->setInstanceId($instanceId) + ->setInstance($instance); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $provisioningClient->createInstance($formattedParent, $instanceId, $instance); + $response = $provisioningClient->createInstance($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/ApigeeRegistry/samples/V1/ProvisioningClient/delete_instance.php b/ApigeeRegistry/samples/V1/ProvisioningClient/delete_instance.php index e017de64da8f..83d8f152810f 100644 --- a/ApigeeRegistry/samples/V1/ProvisioningClient/delete_instance.php +++ b/ApigeeRegistry/samples/V1/ProvisioningClient/delete_instance.php @@ -25,7 +25,8 @@ // [START apigeeregistry_v1_generated_Provisioning_DeleteInstance_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\ApigeeRegistry\V1\ProvisioningClient; +use Google\Cloud\ApigeeRegistry\V1\Client\ProvisioningClient; +use Google\Cloud\ApigeeRegistry\V1\DeleteInstanceRequest; use Google\Rpc\Status; /** @@ -40,10 +41,14 @@ function delete_instance_sample(string $formattedName): void // Create a client. $provisioningClient = new ProvisioningClient(); + // Prepare the request message. + $request = (new DeleteInstanceRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $provisioningClient->deleteInstance($formattedName); + $response = $provisioningClient->deleteInstance($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/ApigeeRegistry/samples/V1/ProvisioningClient/get_iam_policy.php b/ApigeeRegistry/samples/V1/ProvisioningClient/get_iam_policy.php index b23007602a16..9f98a2db53c8 100644 --- a/ApigeeRegistry/samples/V1/ProvisioningClient/get_iam_policy.php +++ b/ApigeeRegistry/samples/V1/ProvisioningClient/get_iam_policy.php @@ -24,7 +24,8 @@ // [START apigeeregistry_v1_generated_Provisioning_GetIamPolicy_sync] use Google\ApiCore\ApiException; -use Google\Cloud\ApigeeRegistry\V1\ProvisioningClient; +use Google\Cloud\ApigeeRegistry\V1\Client\ProvisioningClient; +use Google\Cloud\Iam\V1\GetIamPolicyRequest; use Google\Cloud\Iam\V1\Policy; /** @@ -39,10 +40,14 @@ function get_iam_policy_sample(string $resource): void // Create a client. $provisioningClient = new ProvisioningClient(); + // Prepare the request message. + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + // Call the API and handle any network failures. try { /** @var Policy $response */ - $response = $provisioningClient->getIamPolicy($resource); + $response = $provisioningClient->getIamPolicy($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ApigeeRegistry/samples/V1/ProvisioningClient/get_instance.php b/ApigeeRegistry/samples/V1/ProvisioningClient/get_instance.php index e054657d85f3..f348c51f6672 100644 --- a/ApigeeRegistry/samples/V1/ProvisioningClient/get_instance.php +++ b/ApigeeRegistry/samples/V1/ProvisioningClient/get_instance.php @@ -24,8 +24,9 @@ // [START apigeeregistry_v1_generated_Provisioning_GetInstance_sync] use Google\ApiCore\ApiException; +use Google\Cloud\ApigeeRegistry\V1\Client\ProvisioningClient; +use Google\Cloud\ApigeeRegistry\V1\GetInstanceRequest; use Google\Cloud\ApigeeRegistry\V1\Instance; -use Google\Cloud\ApigeeRegistry\V1\ProvisioningClient; /** * Gets details of a single Instance. @@ -39,10 +40,14 @@ function get_instance_sample(string $formattedName): void // Create a client. $provisioningClient = new ProvisioningClient(); + // Prepare the request message. + $request = (new GetInstanceRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var Instance $response */ - $response = $provisioningClient->getInstance($formattedName); + $response = $provisioningClient->getInstance($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ApigeeRegistry/samples/V1/ProvisioningClient/get_location.php b/ApigeeRegistry/samples/V1/ProvisioningClient/get_location.php index ea4c815734fc..ff091b74ceca 100644 --- a/ApigeeRegistry/samples/V1/ProvisioningClient/get_location.php +++ b/ApigeeRegistry/samples/V1/ProvisioningClient/get_location.php @@ -24,7 +24,8 @@ // [START apigeeregistry_v1_generated_Provisioning_GetLocation_sync] use Google\ApiCore\ApiException; -use Google\Cloud\ApigeeRegistry\V1\ProvisioningClient; +use Google\Cloud\ApigeeRegistry\V1\Client\ProvisioningClient; +use Google\Cloud\Location\GetLocationRequest; use Google\Cloud\Location\Location; /** @@ -41,10 +42,13 @@ function get_location_sample(): void // Create a client. $provisioningClient = new ProvisioningClient(); + // Prepare the request message. + $request = new GetLocationRequest(); + // Call the API and handle any network failures. try { /** @var Location $response */ - $response = $provisioningClient->getLocation(); + $response = $provisioningClient->getLocation($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ApigeeRegistry/samples/V1/ProvisioningClient/list_locations.php b/ApigeeRegistry/samples/V1/ProvisioningClient/list_locations.php index d3a28b9002f7..265b2a0395e8 100644 --- a/ApigeeRegistry/samples/V1/ProvisioningClient/list_locations.php +++ b/ApigeeRegistry/samples/V1/ProvisioningClient/list_locations.php @@ -25,7 +25,8 @@ // [START apigeeregistry_v1_generated_Provisioning_ListLocations_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; -use Google\Cloud\ApigeeRegistry\V1\ProvisioningClient; +use Google\Cloud\ApigeeRegistry\V1\Client\ProvisioningClient; +use Google\Cloud\Location\ListLocationsRequest; use Google\Cloud\Location\Location; /** @@ -42,10 +43,13 @@ function list_locations_sample(): void // Create a client. $provisioningClient = new ProvisioningClient(); + // Prepare the request message. + $request = new ListLocationsRequest(); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $provisioningClient->listLocations(); + $response = $provisioningClient->listLocations($request); /** @var Location $element */ foreach ($response as $element) { diff --git a/ApigeeRegistry/samples/V1/ProvisioningClient/set_iam_policy.php b/ApigeeRegistry/samples/V1/ProvisioningClient/set_iam_policy.php index 008fd43ac804..ac628927c190 100644 --- a/ApigeeRegistry/samples/V1/ProvisioningClient/set_iam_policy.php +++ b/ApigeeRegistry/samples/V1/ProvisioningClient/set_iam_policy.php @@ -24,8 +24,9 @@ // [START apigeeregistry_v1_generated_Provisioning_SetIamPolicy_sync] use Google\ApiCore\ApiException; -use Google\Cloud\ApigeeRegistry\V1\ProvisioningClient; +use Google\Cloud\ApigeeRegistry\V1\Client\ProvisioningClient; use Google\Cloud\Iam\V1\Policy; +use Google\Cloud\Iam\V1\SetIamPolicyRequest; /** * Sets the access control policy on the specified resource. Replaces @@ -42,13 +43,16 @@ function set_iam_policy_sample(string $resource): void // Create a client. $provisioningClient = new ProvisioningClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $policy = new Policy(); + $request = (new SetIamPolicyRequest()) + ->setResource($resource) + ->setPolicy($policy); // Call the API and handle any network failures. try { /** @var Policy $response */ - $response = $provisioningClient->setIamPolicy($resource, $policy); + $response = $provisioningClient->setIamPolicy($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ApigeeRegistry/samples/V1/ProvisioningClient/test_iam_permissions.php b/ApigeeRegistry/samples/V1/ProvisioningClient/test_iam_permissions.php index 2685d440ea80..f1e009ee4624 100644 --- a/ApigeeRegistry/samples/V1/ProvisioningClient/test_iam_permissions.php +++ b/ApigeeRegistry/samples/V1/ProvisioningClient/test_iam_permissions.php @@ -24,7 +24,8 @@ // [START apigeeregistry_v1_generated_Provisioning_TestIamPermissions_sync] use Google\ApiCore\ApiException; -use Google\Cloud\ApigeeRegistry\V1\ProvisioningClient; +use Google\Cloud\ApigeeRegistry\V1\Client\ProvisioningClient; +use Google\Cloud\Iam\V1\TestIamPermissionsRequest; use Google\Cloud\Iam\V1\TestIamPermissionsResponse; /** @@ -48,13 +49,16 @@ function test_iam_permissions_sample(string $resource, string $permissionsElemen // Create a client. $provisioningClient = new ProvisioningClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $permissions = [$permissionsElement,]; + $request = (new TestIamPermissionsRequest()) + ->setResource($resource) + ->setPermissions($permissions); // Call the API and handle any network failures. try { /** @var TestIamPermissionsResponse $response */ - $response = $provisioningClient->testIamPermissions($resource, $permissions); + $response = $provisioningClient->testIamPermissions($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ApigeeRegistry/samples/V1/RegistryClient/create_api.php b/ApigeeRegistry/samples/V1/RegistryClient/create_api.php index a7255959f02e..3b2d2e9fc578 100644 --- a/ApigeeRegistry/samples/V1/RegistryClient/create_api.php +++ b/ApigeeRegistry/samples/V1/RegistryClient/create_api.php @@ -25,7 +25,8 @@ // [START apigeeregistry_v1_generated_Registry_CreateApi_sync] use Google\ApiCore\ApiException; use Google\Cloud\ApigeeRegistry\V1\Api; -use Google\Cloud\ApigeeRegistry\V1\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\Client\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\CreateApiRequest; /** * Creates a specified API. @@ -46,13 +47,17 @@ function create_api_sample(string $formattedParent, string $apiId): void // Create a client. $registryClient = new RegistryClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $api = new Api(); + $request = (new CreateApiRequest()) + ->setParent($formattedParent) + ->setApi($api) + ->setApiId($apiId); // Call the API and handle any network failures. try { /** @var Api $response */ - $response = $registryClient->createApi($formattedParent, $api, $apiId); + $response = $registryClient->createApi($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ApigeeRegistry/samples/V1/RegistryClient/create_api_deployment.php b/ApigeeRegistry/samples/V1/RegistryClient/create_api_deployment.php index cb04fe335470..6d3b4f3bbd50 100644 --- a/ApigeeRegistry/samples/V1/RegistryClient/create_api_deployment.php +++ b/ApigeeRegistry/samples/V1/RegistryClient/create_api_deployment.php @@ -25,7 +25,8 @@ // [START apigeeregistry_v1_generated_Registry_CreateApiDeployment_sync] use Google\ApiCore\ApiException; use Google\Cloud\ApigeeRegistry\V1\ApiDeployment; -use Google\Cloud\ApigeeRegistry\V1\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\Client\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\CreateApiDeploymentRequest; /** * Creates a specified deployment. @@ -46,17 +47,17 @@ function create_api_deployment_sample(string $formattedParent, string $apiDeploy // Create a client. $registryClient = new RegistryClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $apiDeployment = new ApiDeployment(); + $request = (new CreateApiDeploymentRequest()) + ->setParent($formattedParent) + ->setApiDeployment($apiDeployment) + ->setApiDeploymentId($apiDeploymentId); // Call the API and handle any network failures. try { /** @var ApiDeployment $response */ - $response = $registryClient->createApiDeployment( - $formattedParent, - $apiDeployment, - $apiDeploymentId - ); + $response = $registryClient->createApiDeployment($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ApigeeRegistry/samples/V1/RegistryClient/create_api_spec.php b/ApigeeRegistry/samples/V1/RegistryClient/create_api_spec.php index eee128c48bb1..7bfefa5933f9 100644 --- a/ApigeeRegistry/samples/V1/RegistryClient/create_api_spec.php +++ b/ApigeeRegistry/samples/V1/RegistryClient/create_api_spec.php @@ -25,7 +25,8 @@ // [START apigeeregistry_v1_generated_Registry_CreateApiSpec_sync] use Google\ApiCore\ApiException; use Google\Cloud\ApigeeRegistry\V1\ApiSpec; -use Google\Cloud\ApigeeRegistry\V1\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\Client\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\CreateApiSpecRequest; /** * Creates a specified spec. @@ -46,13 +47,17 @@ function create_api_spec_sample(string $formattedParent, string $apiSpecId): voi // Create a client. $registryClient = new RegistryClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $apiSpec = new ApiSpec(); + $request = (new CreateApiSpecRequest()) + ->setParent($formattedParent) + ->setApiSpec($apiSpec) + ->setApiSpecId($apiSpecId); // Call the API and handle any network failures. try { /** @var ApiSpec $response */ - $response = $registryClient->createApiSpec($formattedParent, $apiSpec, $apiSpecId); + $response = $registryClient->createApiSpec($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ApigeeRegistry/samples/V1/RegistryClient/create_api_version.php b/ApigeeRegistry/samples/V1/RegistryClient/create_api_version.php index 6fefc0d06638..fd7ad3243b46 100644 --- a/ApigeeRegistry/samples/V1/RegistryClient/create_api_version.php +++ b/ApigeeRegistry/samples/V1/RegistryClient/create_api_version.php @@ -25,7 +25,8 @@ // [START apigeeregistry_v1_generated_Registry_CreateApiVersion_sync] use Google\ApiCore\ApiException; use Google\Cloud\ApigeeRegistry\V1\ApiVersion; -use Google\Cloud\ApigeeRegistry\V1\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\Client\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\CreateApiVersionRequest; /** * Creates a specified version. @@ -46,13 +47,17 @@ function create_api_version_sample(string $formattedParent, string $apiVersionId // Create a client. $registryClient = new RegistryClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $apiVersion = new ApiVersion(); + $request = (new CreateApiVersionRequest()) + ->setParent($formattedParent) + ->setApiVersion($apiVersion) + ->setApiVersionId($apiVersionId); // Call the API and handle any network failures. try { /** @var ApiVersion $response */ - $response = $registryClient->createApiVersion($formattedParent, $apiVersion, $apiVersionId); + $response = $registryClient->createApiVersion($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ApigeeRegistry/samples/V1/RegistryClient/create_artifact.php b/ApigeeRegistry/samples/V1/RegistryClient/create_artifact.php index 07cf722af20a..4cdd3249c8e2 100644 --- a/ApigeeRegistry/samples/V1/RegistryClient/create_artifact.php +++ b/ApigeeRegistry/samples/V1/RegistryClient/create_artifact.php @@ -25,7 +25,8 @@ // [START apigeeregistry_v1_generated_Registry_CreateArtifact_sync] use Google\ApiCore\ApiException; use Google\Cloud\ApigeeRegistry\V1\Artifact; -use Google\Cloud\ApigeeRegistry\V1\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\Client\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\CreateArtifactRequest; /** * Creates a specified artifact. @@ -46,13 +47,17 @@ function create_artifact_sample(string $formattedParent, string $artifactId): vo // Create a client. $registryClient = new RegistryClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $artifact = new Artifact(); + $request = (new CreateArtifactRequest()) + ->setParent($formattedParent) + ->setArtifact($artifact) + ->setArtifactId($artifactId); // Call the API and handle any network failures. try { /** @var Artifact $response */ - $response = $registryClient->createArtifact($formattedParent, $artifact, $artifactId); + $response = $registryClient->createArtifact($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ApigeeRegistry/samples/V1/RegistryClient/delete_api.php b/ApigeeRegistry/samples/V1/RegistryClient/delete_api.php index 974259d4abe9..fdc789fd6446 100644 --- a/ApigeeRegistry/samples/V1/RegistryClient/delete_api.php +++ b/ApigeeRegistry/samples/V1/RegistryClient/delete_api.php @@ -24,7 +24,8 @@ // [START apigeeregistry_v1_generated_Registry_DeleteApi_sync] use Google\ApiCore\ApiException; -use Google\Cloud\ApigeeRegistry\V1\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\Client\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\DeleteApiRequest; /** * Removes a specified API and all of the resources that it @@ -39,9 +40,13 @@ function delete_api_sample(string $formattedName): void // Create a client. $registryClient = new RegistryClient(); + // Prepare the request message. + $request = (new DeleteApiRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { - $registryClient->deleteApi($formattedName); + $registryClient->deleteApi($request); printf('Call completed successfully.' . PHP_EOL); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ApigeeRegistry/samples/V1/RegistryClient/delete_api_deployment.php b/ApigeeRegistry/samples/V1/RegistryClient/delete_api_deployment.php index 6d8c7646eff8..2a9c94beecd5 100644 --- a/ApigeeRegistry/samples/V1/RegistryClient/delete_api_deployment.php +++ b/ApigeeRegistry/samples/V1/RegistryClient/delete_api_deployment.php @@ -24,7 +24,8 @@ // [START apigeeregistry_v1_generated_Registry_DeleteApiDeployment_sync] use Google\ApiCore\ApiException; -use Google\Cloud\ApigeeRegistry\V1\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\Client\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\DeleteApiDeploymentRequest; /** * Removes a specified deployment, all revisions, and all @@ -39,9 +40,13 @@ function delete_api_deployment_sample(string $formattedName): void // Create a client. $registryClient = new RegistryClient(); + // Prepare the request message. + $request = (new DeleteApiDeploymentRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { - $registryClient->deleteApiDeployment($formattedName); + $registryClient->deleteApiDeployment($request); printf('Call completed successfully.' . PHP_EOL); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ApigeeRegistry/samples/V1/RegistryClient/delete_api_deployment_revision.php b/ApigeeRegistry/samples/V1/RegistryClient/delete_api_deployment_revision.php index 68af98ea1b6e..0ae70a39cbd9 100644 --- a/ApigeeRegistry/samples/V1/RegistryClient/delete_api_deployment_revision.php +++ b/ApigeeRegistry/samples/V1/RegistryClient/delete_api_deployment_revision.php @@ -25,7 +25,8 @@ // [START apigeeregistry_v1_generated_Registry_DeleteApiDeploymentRevision_sync] use Google\ApiCore\ApiException; use Google\Cloud\ApigeeRegistry\V1\ApiDeployment; -use Google\Cloud\ApigeeRegistry\V1\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\Client\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\DeleteApiDeploymentRevisionRequest; /** * Deletes a revision of a deployment. @@ -42,10 +43,14 @@ function delete_api_deployment_revision_sample(string $formattedName): void // Create a client. $registryClient = new RegistryClient(); + // Prepare the request message. + $request = (new DeleteApiDeploymentRevisionRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var ApiDeployment $response */ - $response = $registryClient->deleteApiDeploymentRevision($formattedName); + $response = $registryClient->deleteApiDeploymentRevision($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ApigeeRegistry/samples/V1/RegistryClient/delete_api_spec.php b/ApigeeRegistry/samples/V1/RegistryClient/delete_api_spec.php index f41aa726c5bd..252705f0d108 100644 --- a/ApigeeRegistry/samples/V1/RegistryClient/delete_api_spec.php +++ b/ApigeeRegistry/samples/V1/RegistryClient/delete_api_spec.php @@ -24,7 +24,8 @@ // [START apigeeregistry_v1_generated_Registry_DeleteApiSpec_sync] use Google\ApiCore\ApiException; -use Google\Cloud\ApigeeRegistry\V1\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\Client\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\DeleteApiSpecRequest; /** * Removes a specified spec, all revisions, and all child @@ -39,9 +40,13 @@ function delete_api_spec_sample(string $formattedName): void // Create a client. $registryClient = new RegistryClient(); + // Prepare the request message. + $request = (new DeleteApiSpecRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { - $registryClient->deleteApiSpec($formattedName); + $registryClient->deleteApiSpec($request); printf('Call completed successfully.' . PHP_EOL); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ApigeeRegistry/samples/V1/RegistryClient/delete_api_spec_revision.php b/ApigeeRegistry/samples/V1/RegistryClient/delete_api_spec_revision.php index fe91ce08a23d..e735f380b23d 100644 --- a/ApigeeRegistry/samples/V1/RegistryClient/delete_api_spec_revision.php +++ b/ApigeeRegistry/samples/V1/RegistryClient/delete_api_spec_revision.php @@ -25,7 +25,8 @@ // [START apigeeregistry_v1_generated_Registry_DeleteApiSpecRevision_sync] use Google\ApiCore\ApiException; use Google\Cloud\ApigeeRegistry\V1\ApiSpec; -use Google\Cloud\ApigeeRegistry\V1\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\Client\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\DeleteApiSpecRevisionRequest; /** * Deletes a revision of a spec. @@ -42,10 +43,14 @@ function delete_api_spec_revision_sample(string $formattedName): void // Create a client. $registryClient = new RegistryClient(); + // Prepare the request message. + $request = (new DeleteApiSpecRevisionRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var ApiSpec $response */ - $response = $registryClient->deleteApiSpecRevision($formattedName); + $response = $registryClient->deleteApiSpecRevision($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ApigeeRegistry/samples/V1/RegistryClient/delete_api_version.php b/ApigeeRegistry/samples/V1/RegistryClient/delete_api_version.php index d8f74d06e84d..a6653b4248a4 100644 --- a/ApigeeRegistry/samples/V1/RegistryClient/delete_api_version.php +++ b/ApigeeRegistry/samples/V1/RegistryClient/delete_api_version.php @@ -24,7 +24,8 @@ // [START apigeeregistry_v1_generated_Registry_DeleteApiVersion_sync] use Google\ApiCore\ApiException; -use Google\Cloud\ApigeeRegistry\V1\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\Client\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\DeleteApiVersionRequest; /** * Removes a specified version and all of the resources that @@ -39,9 +40,13 @@ function delete_api_version_sample(string $formattedName): void // Create a client. $registryClient = new RegistryClient(); + // Prepare the request message. + $request = (new DeleteApiVersionRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { - $registryClient->deleteApiVersion($formattedName); + $registryClient->deleteApiVersion($request); printf('Call completed successfully.' . PHP_EOL); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ApigeeRegistry/samples/V1/RegistryClient/delete_artifact.php b/ApigeeRegistry/samples/V1/RegistryClient/delete_artifact.php index c6552e7e93b4..b8ba60bd5c19 100644 --- a/ApigeeRegistry/samples/V1/RegistryClient/delete_artifact.php +++ b/ApigeeRegistry/samples/V1/RegistryClient/delete_artifact.php @@ -24,7 +24,8 @@ // [START apigeeregistry_v1_generated_Registry_DeleteArtifact_sync] use Google\ApiCore\ApiException; -use Google\Cloud\ApigeeRegistry\V1\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\Client\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\DeleteArtifactRequest; /** * Removes a specified artifact. @@ -38,9 +39,13 @@ function delete_artifact_sample(string $formattedName): void // Create a client. $registryClient = new RegistryClient(); + // Prepare the request message. + $request = (new DeleteArtifactRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { - $registryClient->deleteArtifact($formattedName); + $registryClient->deleteArtifact($request); printf('Call completed successfully.' . PHP_EOL); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ApigeeRegistry/samples/V1/RegistryClient/get_api.php b/ApigeeRegistry/samples/V1/RegistryClient/get_api.php index 16c712f335ba..10c0f0a9993b 100644 --- a/ApigeeRegistry/samples/V1/RegistryClient/get_api.php +++ b/ApigeeRegistry/samples/V1/RegistryClient/get_api.php @@ -25,7 +25,8 @@ // [START apigeeregistry_v1_generated_Registry_GetApi_sync] use Google\ApiCore\ApiException; use Google\Cloud\ApigeeRegistry\V1\Api; -use Google\Cloud\ApigeeRegistry\V1\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\Client\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\GetApiRequest; /** * Returns a specified API. @@ -39,10 +40,14 @@ function get_api_sample(string $formattedName): void // Create a client. $registryClient = new RegistryClient(); + // Prepare the request message. + $request = (new GetApiRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var Api $response */ - $response = $registryClient->getApi($formattedName); + $response = $registryClient->getApi($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ApigeeRegistry/samples/V1/RegistryClient/get_api_deployment.php b/ApigeeRegistry/samples/V1/RegistryClient/get_api_deployment.php index 2b0331c1df05..6228ec1a7197 100644 --- a/ApigeeRegistry/samples/V1/RegistryClient/get_api_deployment.php +++ b/ApigeeRegistry/samples/V1/RegistryClient/get_api_deployment.php @@ -25,7 +25,8 @@ // [START apigeeregistry_v1_generated_Registry_GetApiDeployment_sync] use Google\ApiCore\ApiException; use Google\Cloud\ApigeeRegistry\V1\ApiDeployment; -use Google\Cloud\ApigeeRegistry\V1\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\Client\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\GetApiDeploymentRequest; /** * Returns a specified deployment. @@ -39,10 +40,14 @@ function get_api_deployment_sample(string $formattedName): void // Create a client. $registryClient = new RegistryClient(); + // Prepare the request message. + $request = (new GetApiDeploymentRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var ApiDeployment $response */ - $response = $registryClient->getApiDeployment($formattedName); + $response = $registryClient->getApiDeployment($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ApigeeRegistry/samples/V1/RegistryClient/get_api_spec.php b/ApigeeRegistry/samples/V1/RegistryClient/get_api_spec.php index 079f8a866f3c..aab3c43fff8e 100644 --- a/ApigeeRegistry/samples/V1/RegistryClient/get_api_spec.php +++ b/ApigeeRegistry/samples/V1/RegistryClient/get_api_spec.php @@ -25,7 +25,8 @@ // [START apigeeregistry_v1_generated_Registry_GetApiSpec_sync] use Google\ApiCore\ApiException; use Google\Cloud\ApigeeRegistry\V1\ApiSpec; -use Google\Cloud\ApigeeRegistry\V1\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\Client\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\GetApiSpecRequest; /** * Returns a specified spec. @@ -39,10 +40,14 @@ function get_api_spec_sample(string $formattedName): void // Create a client. $registryClient = new RegistryClient(); + // Prepare the request message. + $request = (new GetApiSpecRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var ApiSpec $response */ - $response = $registryClient->getApiSpec($formattedName); + $response = $registryClient->getApiSpec($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ApigeeRegistry/samples/V1/RegistryClient/get_api_spec_contents.php b/ApigeeRegistry/samples/V1/RegistryClient/get_api_spec_contents.php index 9c1775b0cbb9..c0e3ed038a9b 100644 --- a/ApigeeRegistry/samples/V1/RegistryClient/get_api_spec_contents.php +++ b/ApigeeRegistry/samples/V1/RegistryClient/get_api_spec_contents.php @@ -25,7 +25,8 @@ // [START apigeeregistry_v1_generated_Registry_GetApiSpecContents_sync] use Google\ApiCore\ApiException; use Google\Api\HttpBody; -use Google\Cloud\ApigeeRegistry\V1\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\Client\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\GetApiSpecContentsRequest; /** * Returns the contents of a specified spec. @@ -42,10 +43,14 @@ function get_api_spec_contents_sample(string $formattedName): void // Create a client. $registryClient = new RegistryClient(); + // Prepare the request message. + $request = (new GetApiSpecContentsRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var HttpBody $response */ - $response = $registryClient->getApiSpecContents($formattedName); + $response = $registryClient->getApiSpecContents($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ApigeeRegistry/samples/V1/RegistryClient/get_api_version.php b/ApigeeRegistry/samples/V1/RegistryClient/get_api_version.php index f6ba7eee7c4d..091ede9c6db4 100644 --- a/ApigeeRegistry/samples/V1/RegistryClient/get_api_version.php +++ b/ApigeeRegistry/samples/V1/RegistryClient/get_api_version.php @@ -25,7 +25,8 @@ // [START apigeeregistry_v1_generated_Registry_GetApiVersion_sync] use Google\ApiCore\ApiException; use Google\Cloud\ApigeeRegistry\V1\ApiVersion; -use Google\Cloud\ApigeeRegistry\V1\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\Client\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\GetApiVersionRequest; /** * Returns a specified version. @@ -39,10 +40,14 @@ function get_api_version_sample(string $formattedName): void // Create a client. $registryClient = new RegistryClient(); + // Prepare the request message. + $request = (new GetApiVersionRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var ApiVersion $response */ - $response = $registryClient->getApiVersion($formattedName); + $response = $registryClient->getApiVersion($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ApigeeRegistry/samples/V1/RegistryClient/get_artifact.php b/ApigeeRegistry/samples/V1/RegistryClient/get_artifact.php index 459faac8b632..f702a37cf5a6 100644 --- a/ApigeeRegistry/samples/V1/RegistryClient/get_artifact.php +++ b/ApigeeRegistry/samples/V1/RegistryClient/get_artifact.php @@ -25,7 +25,8 @@ // [START apigeeregistry_v1_generated_Registry_GetArtifact_sync] use Google\ApiCore\ApiException; use Google\Cloud\ApigeeRegistry\V1\Artifact; -use Google\Cloud\ApigeeRegistry\V1\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\Client\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\GetArtifactRequest; /** * Returns a specified artifact. @@ -39,10 +40,14 @@ function get_artifact_sample(string $formattedName): void // Create a client. $registryClient = new RegistryClient(); + // Prepare the request message. + $request = (new GetArtifactRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var Artifact $response */ - $response = $registryClient->getArtifact($formattedName); + $response = $registryClient->getArtifact($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ApigeeRegistry/samples/V1/RegistryClient/get_artifact_contents.php b/ApigeeRegistry/samples/V1/RegistryClient/get_artifact_contents.php index 7def877efa7d..e11ff2473a3f 100644 --- a/ApigeeRegistry/samples/V1/RegistryClient/get_artifact_contents.php +++ b/ApigeeRegistry/samples/V1/RegistryClient/get_artifact_contents.php @@ -25,7 +25,8 @@ // [START apigeeregistry_v1_generated_Registry_GetArtifactContents_sync] use Google\ApiCore\ApiException; use Google\Api\HttpBody; -use Google\Cloud\ApigeeRegistry\V1\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\Client\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\GetArtifactContentsRequest; /** * Returns the contents of a specified artifact. @@ -42,10 +43,14 @@ function get_artifact_contents_sample(string $formattedName): void // Create a client. $registryClient = new RegistryClient(); + // Prepare the request message. + $request = (new GetArtifactContentsRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var HttpBody $response */ - $response = $registryClient->getArtifactContents($formattedName); + $response = $registryClient->getArtifactContents($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ApigeeRegistry/samples/V1/RegistryClient/get_iam_policy.php b/ApigeeRegistry/samples/V1/RegistryClient/get_iam_policy.php index b4db8d7931b1..b8d2149456b3 100644 --- a/ApigeeRegistry/samples/V1/RegistryClient/get_iam_policy.php +++ b/ApigeeRegistry/samples/V1/RegistryClient/get_iam_policy.php @@ -24,7 +24,8 @@ // [START apigeeregistry_v1_generated_Registry_GetIamPolicy_sync] use Google\ApiCore\ApiException; -use Google\Cloud\ApigeeRegistry\V1\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\Client\RegistryClient; +use Google\Cloud\Iam\V1\GetIamPolicyRequest; use Google\Cloud\Iam\V1\Policy; /** @@ -39,10 +40,14 @@ function get_iam_policy_sample(string $resource): void // Create a client. $registryClient = new RegistryClient(); + // Prepare the request message. + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + // Call the API and handle any network failures. try { /** @var Policy $response */ - $response = $registryClient->getIamPolicy($resource); + $response = $registryClient->getIamPolicy($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ApigeeRegistry/samples/V1/RegistryClient/get_location.php b/ApigeeRegistry/samples/V1/RegistryClient/get_location.php index df19f971ae58..82a8e28a76a9 100644 --- a/ApigeeRegistry/samples/V1/RegistryClient/get_location.php +++ b/ApigeeRegistry/samples/V1/RegistryClient/get_location.php @@ -24,7 +24,8 @@ // [START apigeeregistry_v1_generated_Registry_GetLocation_sync] use Google\ApiCore\ApiException; -use Google\Cloud\ApigeeRegistry\V1\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\Client\RegistryClient; +use Google\Cloud\Location\GetLocationRequest; use Google\Cloud\Location\Location; /** @@ -41,10 +42,13 @@ function get_location_sample(): void // Create a client. $registryClient = new RegistryClient(); + // Prepare the request message. + $request = new GetLocationRequest(); + // Call the API and handle any network failures. try { /** @var Location $response */ - $response = $registryClient->getLocation(); + $response = $registryClient->getLocation($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ApigeeRegistry/samples/V1/RegistryClient/list_api_deployment_revisions.php b/ApigeeRegistry/samples/V1/RegistryClient/list_api_deployment_revisions.php index 71ec8ef06934..3a68e3f09764 100644 --- a/ApigeeRegistry/samples/V1/RegistryClient/list_api_deployment_revisions.php +++ b/ApigeeRegistry/samples/V1/RegistryClient/list_api_deployment_revisions.php @@ -26,7 +26,8 @@ use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; use Google\Cloud\ApigeeRegistry\V1\ApiDeployment; -use Google\Cloud\ApigeeRegistry\V1\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\Client\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\ListApiDeploymentRevisionsRequest; /** * Lists all revisions of a deployment. @@ -40,10 +41,14 @@ function list_api_deployment_revisions_sample(string $formattedName): void // Create a client. $registryClient = new RegistryClient(); + // Prepare the request message. + $request = (new ListApiDeploymentRevisionsRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $registryClient->listApiDeploymentRevisions($formattedName); + $response = $registryClient->listApiDeploymentRevisions($request); /** @var ApiDeployment $element */ foreach ($response as $element) { diff --git a/ApigeeRegistry/samples/V1/RegistryClient/list_api_deployments.php b/ApigeeRegistry/samples/V1/RegistryClient/list_api_deployments.php index e92c589f4293..05e87dc2fe64 100644 --- a/ApigeeRegistry/samples/V1/RegistryClient/list_api_deployments.php +++ b/ApigeeRegistry/samples/V1/RegistryClient/list_api_deployments.php @@ -26,7 +26,8 @@ use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; use Google\Cloud\ApigeeRegistry\V1\ApiDeployment; -use Google\Cloud\ApigeeRegistry\V1\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\Client\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\ListApiDeploymentsRequest; /** * Returns matching deployments. @@ -40,10 +41,14 @@ function list_api_deployments_sample(string $formattedParent): void // Create a client. $registryClient = new RegistryClient(); + // Prepare the request message. + $request = (new ListApiDeploymentsRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $registryClient->listApiDeployments($formattedParent); + $response = $registryClient->listApiDeployments($request); /** @var ApiDeployment $element */ foreach ($response as $element) { diff --git a/ApigeeRegistry/samples/V1/RegistryClient/list_api_spec_revisions.php b/ApigeeRegistry/samples/V1/RegistryClient/list_api_spec_revisions.php index bcaca72bf75b..b5a37e1f2295 100644 --- a/ApigeeRegistry/samples/V1/RegistryClient/list_api_spec_revisions.php +++ b/ApigeeRegistry/samples/V1/RegistryClient/list_api_spec_revisions.php @@ -26,7 +26,8 @@ use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; use Google\Cloud\ApigeeRegistry\V1\ApiSpec; -use Google\Cloud\ApigeeRegistry\V1\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\Client\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\ListApiSpecRevisionsRequest; /** * Lists all revisions of a spec. @@ -40,10 +41,14 @@ function list_api_spec_revisions_sample(string $formattedName): void // Create a client. $registryClient = new RegistryClient(); + // Prepare the request message. + $request = (new ListApiSpecRevisionsRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $registryClient->listApiSpecRevisions($formattedName); + $response = $registryClient->listApiSpecRevisions($request); /** @var ApiSpec $element */ foreach ($response as $element) { diff --git a/ApigeeRegistry/samples/V1/RegistryClient/list_api_specs.php b/ApigeeRegistry/samples/V1/RegistryClient/list_api_specs.php index 91cfd4afc19c..be7c7d254614 100644 --- a/ApigeeRegistry/samples/V1/RegistryClient/list_api_specs.php +++ b/ApigeeRegistry/samples/V1/RegistryClient/list_api_specs.php @@ -26,7 +26,8 @@ use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; use Google\Cloud\ApigeeRegistry\V1\ApiSpec; -use Google\Cloud\ApigeeRegistry\V1\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\Client\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\ListApiSpecsRequest; /** * Returns matching specs. @@ -40,10 +41,14 @@ function list_api_specs_sample(string $formattedParent): void // Create a client. $registryClient = new RegistryClient(); + // Prepare the request message. + $request = (new ListApiSpecsRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $registryClient->listApiSpecs($formattedParent); + $response = $registryClient->listApiSpecs($request); /** @var ApiSpec $element */ foreach ($response as $element) { diff --git a/ApigeeRegistry/samples/V1/RegistryClient/list_api_versions.php b/ApigeeRegistry/samples/V1/RegistryClient/list_api_versions.php index 19ff0212ff32..349c5bf2334e 100644 --- a/ApigeeRegistry/samples/V1/RegistryClient/list_api_versions.php +++ b/ApigeeRegistry/samples/V1/RegistryClient/list_api_versions.php @@ -26,7 +26,8 @@ use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; use Google\Cloud\ApigeeRegistry\V1\ApiVersion; -use Google\Cloud\ApigeeRegistry\V1\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\Client\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\ListApiVersionsRequest; /** * Returns matching versions. @@ -40,10 +41,14 @@ function list_api_versions_sample(string $formattedParent): void // Create a client. $registryClient = new RegistryClient(); + // Prepare the request message. + $request = (new ListApiVersionsRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $registryClient->listApiVersions($formattedParent); + $response = $registryClient->listApiVersions($request); /** @var ApiVersion $element */ foreach ($response as $element) { diff --git a/ApigeeRegistry/samples/V1/RegistryClient/list_apis.php b/ApigeeRegistry/samples/V1/RegistryClient/list_apis.php index 005b7e40e45f..32cde7d46edc 100644 --- a/ApigeeRegistry/samples/V1/RegistryClient/list_apis.php +++ b/ApigeeRegistry/samples/V1/RegistryClient/list_apis.php @@ -26,7 +26,8 @@ use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; use Google\Cloud\ApigeeRegistry\V1\Api; -use Google\Cloud\ApigeeRegistry\V1\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\Client\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\ListApisRequest; /** * Returns matching APIs. @@ -40,10 +41,14 @@ function list_apis_sample(string $formattedParent): void // Create a client. $registryClient = new RegistryClient(); + // Prepare the request message. + $request = (new ListApisRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $registryClient->listApis($formattedParent); + $response = $registryClient->listApis($request); /** @var Api $element */ foreach ($response as $element) { diff --git a/ApigeeRegistry/samples/V1/RegistryClient/list_artifacts.php b/ApigeeRegistry/samples/V1/RegistryClient/list_artifacts.php index 6870e42adb6b..befd0b55a657 100644 --- a/ApigeeRegistry/samples/V1/RegistryClient/list_artifacts.php +++ b/ApigeeRegistry/samples/V1/RegistryClient/list_artifacts.php @@ -26,7 +26,8 @@ use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; use Google\Cloud\ApigeeRegistry\V1\Artifact; -use Google\Cloud\ApigeeRegistry\V1\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\Client\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\ListArtifactsRequest; /** * Returns matching artifacts. @@ -40,10 +41,14 @@ function list_artifacts_sample(string $formattedParent): void // Create a client. $registryClient = new RegistryClient(); + // Prepare the request message. + $request = (new ListArtifactsRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $registryClient->listArtifacts($formattedParent); + $response = $registryClient->listArtifacts($request); /** @var Artifact $element */ foreach ($response as $element) { diff --git a/ApigeeRegistry/samples/V1/RegistryClient/list_locations.php b/ApigeeRegistry/samples/V1/RegistryClient/list_locations.php index bfc62eba3061..d9b080aeaeb6 100644 --- a/ApigeeRegistry/samples/V1/RegistryClient/list_locations.php +++ b/ApigeeRegistry/samples/V1/RegistryClient/list_locations.php @@ -25,7 +25,8 @@ // [START apigeeregistry_v1_generated_Registry_ListLocations_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; -use Google\Cloud\ApigeeRegistry\V1\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\Client\RegistryClient; +use Google\Cloud\Location\ListLocationsRequest; use Google\Cloud\Location\Location; /** @@ -42,10 +43,13 @@ function list_locations_sample(): void // Create a client. $registryClient = new RegistryClient(); + // Prepare the request message. + $request = new ListLocationsRequest(); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $registryClient->listLocations(); + $response = $registryClient->listLocations($request); /** @var Location $element */ foreach ($response as $element) { diff --git a/ApigeeRegistry/samples/V1/RegistryClient/replace_artifact.php b/ApigeeRegistry/samples/V1/RegistryClient/replace_artifact.php index 1521d8d47345..4bde9aaf9fc5 100644 --- a/ApigeeRegistry/samples/V1/RegistryClient/replace_artifact.php +++ b/ApigeeRegistry/samples/V1/RegistryClient/replace_artifact.php @@ -25,7 +25,8 @@ // [START apigeeregistry_v1_generated_Registry_ReplaceArtifact_sync] use Google\ApiCore\ApiException; use Google\Cloud\ApigeeRegistry\V1\Artifact; -use Google\Cloud\ApigeeRegistry\V1\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\Client\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\ReplaceArtifactRequest; /** * Used to replace a specified artifact. @@ -41,13 +42,15 @@ function replace_artifact_sample(): void // Create a client. $registryClient = new RegistryClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $artifact = new Artifact(); + $request = (new ReplaceArtifactRequest()) + ->setArtifact($artifact); // Call the API and handle any network failures. try { /** @var Artifact $response */ - $response = $registryClient->replaceArtifact($artifact); + $response = $registryClient->replaceArtifact($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ApigeeRegistry/samples/V1/RegistryClient/rollback_api_deployment.php b/ApigeeRegistry/samples/V1/RegistryClient/rollback_api_deployment.php index 54cb67da61ef..866b0bd4ac85 100644 --- a/ApigeeRegistry/samples/V1/RegistryClient/rollback_api_deployment.php +++ b/ApigeeRegistry/samples/V1/RegistryClient/rollback_api_deployment.php @@ -25,7 +25,8 @@ // [START apigeeregistry_v1_generated_Registry_RollbackApiDeployment_sync] use Google\ApiCore\ApiException; use Google\Cloud\ApigeeRegistry\V1\ApiDeployment; -use Google\Cloud\ApigeeRegistry\V1\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\Client\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\RollbackApiDeploymentRequest; /** * Sets the current revision to a specified prior @@ -43,10 +44,15 @@ function rollback_api_deployment_sample(string $formattedName, string $revisionI // Create a client. $registryClient = new RegistryClient(); + // Prepare the request message. + $request = (new RollbackApiDeploymentRequest()) + ->setName($formattedName) + ->setRevisionId($revisionId); + // Call the API and handle any network failures. try { /** @var ApiDeployment $response */ - $response = $registryClient->rollbackApiDeployment($formattedName, $revisionId); + $response = $registryClient->rollbackApiDeployment($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ApigeeRegistry/samples/V1/RegistryClient/rollback_api_spec.php b/ApigeeRegistry/samples/V1/RegistryClient/rollback_api_spec.php index b3cdd251f793..f2fdee566df4 100644 --- a/ApigeeRegistry/samples/V1/RegistryClient/rollback_api_spec.php +++ b/ApigeeRegistry/samples/V1/RegistryClient/rollback_api_spec.php @@ -25,7 +25,8 @@ // [START apigeeregistry_v1_generated_Registry_RollbackApiSpec_sync] use Google\ApiCore\ApiException; use Google\Cloud\ApigeeRegistry\V1\ApiSpec; -use Google\Cloud\ApigeeRegistry\V1\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\Client\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\RollbackApiSpecRequest; /** * Sets the current revision to a specified prior revision. @@ -43,10 +44,15 @@ function rollback_api_spec_sample(string $formattedName, string $revisionId): vo // Create a client. $registryClient = new RegistryClient(); + // Prepare the request message. + $request = (new RollbackApiSpecRequest()) + ->setName($formattedName) + ->setRevisionId($revisionId); + // Call the API and handle any network failures. try { /** @var ApiSpec $response */ - $response = $registryClient->rollbackApiSpec($formattedName, $revisionId); + $response = $registryClient->rollbackApiSpec($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ApigeeRegistry/samples/V1/RegistryClient/set_iam_policy.php b/ApigeeRegistry/samples/V1/RegistryClient/set_iam_policy.php index ee1ccc46e5c1..b6cbbaf0d2ec 100644 --- a/ApigeeRegistry/samples/V1/RegistryClient/set_iam_policy.php +++ b/ApigeeRegistry/samples/V1/RegistryClient/set_iam_policy.php @@ -24,8 +24,9 @@ // [START apigeeregistry_v1_generated_Registry_SetIamPolicy_sync] use Google\ApiCore\ApiException; -use Google\Cloud\ApigeeRegistry\V1\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\Client\RegistryClient; use Google\Cloud\Iam\V1\Policy; +use Google\Cloud\Iam\V1\SetIamPolicyRequest; /** * Sets the access control policy on the specified resource. Replaces @@ -42,13 +43,16 @@ function set_iam_policy_sample(string $resource): void // Create a client. $registryClient = new RegistryClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $policy = new Policy(); + $request = (new SetIamPolicyRequest()) + ->setResource($resource) + ->setPolicy($policy); // Call the API and handle any network failures. try { /** @var Policy $response */ - $response = $registryClient->setIamPolicy($resource, $policy); + $response = $registryClient->setIamPolicy($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ApigeeRegistry/samples/V1/RegistryClient/tag_api_deployment_revision.php b/ApigeeRegistry/samples/V1/RegistryClient/tag_api_deployment_revision.php index faaaa935ce66..3c1b18b001c0 100644 --- a/ApigeeRegistry/samples/V1/RegistryClient/tag_api_deployment_revision.php +++ b/ApigeeRegistry/samples/V1/RegistryClient/tag_api_deployment_revision.php @@ -25,7 +25,8 @@ // [START apigeeregistry_v1_generated_Registry_TagApiDeploymentRevision_sync] use Google\ApiCore\ApiException; use Google\Cloud\ApigeeRegistry\V1\ApiDeployment; -use Google\Cloud\ApigeeRegistry\V1\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\Client\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\TagApiDeploymentRevisionRequest; /** * Adds a tag to a specified revision of a @@ -41,10 +42,15 @@ function tag_api_deployment_revision_sample(string $formattedName, string $tag): // Create a client. $registryClient = new RegistryClient(); + // Prepare the request message. + $request = (new TagApiDeploymentRevisionRequest()) + ->setName($formattedName) + ->setTag($tag); + // Call the API and handle any network failures. try { /** @var ApiDeployment $response */ - $response = $registryClient->tagApiDeploymentRevision($formattedName, $tag); + $response = $registryClient->tagApiDeploymentRevision($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ApigeeRegistry/samples/V1/RegistryClient/tag_api_spec_revision.php b/ApigeeRegistry/samples/V1/RegistryClient/tag_api_spec_revision.php index 228dcf468aac..6a382a50996d 100644 --- a/ApigeeRegistry/samples/V1/RegistryClient/tag_api_spec_revision.php +++ b/ApigeeRegistry/samples/V1/RegistryClient/tag_api_spec_revision.php @@ -25,7 +25,8 @@ // [START apigeeregistry_v1_generated_Registry_TagApiSpecRevision_sync] use Google\ApiCore\ApiException; use Google\Cloud\ApigeeRegistry\V1\ApiSpec; -use Google\Cloud\ApigeeRegistry\V1\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\Client\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\TagApiSpecRevisionRequest; /** * Adds a tag to a specified revision of a spec. @@ -40,10 +41,15 @@ function tag_api_spec_revision_sample(string $formattedName, string $tag): void // Create a client. $registryClient = new RegistryClient(); + // Prepare the request message. + $request = (new TagApiSpecRevisionRequest()) + ->setName($formattedName) + ->setTag($tag); + // Call the API and handle any network failures. try { /** @var ApiSpec $response */ - $response = $registryClient->tagApiSpecRevision($formattedName, $tag); + $response = $registryClient->tagApiSpecRevision($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ApigeeRegistry/samples/V1/RegistryClient/test_iam_permissions.php b/ApigeeRegistry/samples/V1/RegistryClient/test_iam_permissions.php index bb595c569764..4f721072c47a 100644 --- a/ApigeeRegistry/samples/V1/RegistryClient/test_iam_permissions.php +++ b/ApigeeRegistry/samples/V1/RegistryClient/test_iam_permissions.php @@ -24,7 +24,8 @@ // [START apigeeregistry_v1_generated_Registry_TestIamPermissions_sync] use Google\ApiCore\ApiException; -use Google\Cloud\ApigeeRegistry\V1\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\Client\RegistryClient; +use Google\Cloud\Iam\V1\TestIamPermissionsRequest; use Google\Cloud\Iam\V1\TestIamPermissionsResponse; /** @@ -48,13 +49,16 @@ function test_iam_permissions_sample(string $resource, string $permissionsElemen // Create a client. $registryClient = new RegistryClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $permissions = [$permissionsElement,]; + $request = (new TestIamPermissionsRequest()) + ->setResource($resource) + ->setPermissions($permissions); // Call the API and handle any network failures. try { /** @var TestIamPermissionsResponse $response */ - $response = $registryClient->testIamPermissions($resource, $permissions); + $response = $registryClient->testIamPermissions($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ApigeeRegistry/samples/V1/RegistryClient/update_api.php b/ApigeeRegistry/samples/V1/RegistryClient/update_api.php index 65b1eea75543..be70d577cb3f 100644 --- a/ApigeeRegistry/samples/V1/RegistryClient/update_api.php +++ b/ApigeeRegistry/samples/V1/RegistryClient/update_api.php @@ -25,7 +25,8 @@ // [START apigeeregistry_v1_generated_Registry_UpdateApi_sync] use Google\ApiCore\ApiException; use Google\Cloud\ApigeeRegistry\V1\Api; -use Google\Cloud\ApigeeRegistry\V1\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\Client\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\UpdateApiRequest; /** * Used to modify a specified API. @@ -41,13 +42,15 @@ function update_api_sample(): void // Create a client. $registryClient = new RegistryClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $api = new Api(); + $request = (new UpdateApiRequest()) + ->setApi($api); // Call the API and handle any network failures. try { /** @var Api $response */ - $response = $registryClient->updateApi($api); + $response = $registryClient->updateApi($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ApigeeRegistry/samples/V1/RegistryClient/update_api_deployment.php b/ApigeeRegistry/samples/V1/RegistryClient/update_api_deployment.php index 21a6915d87ac..6de2e8c8f56a 100644 --- a/ApigeeRegistry/samples/V1/RegistryClient/update_api_deployment.php +++ b/ApigeeRegistry/samples/V1/RegistryClient/update_api_deployment.php @@ -25,7 +25,8 @@ // [START apigeeregistry_v1_generated_Registry_UpdateApiDeployment_sync] use Google\ApiCore\ApiException; use Google\Cloud\ApigeeRegistry\V1\ApiDeployment; -use Google\Cloud\ApigeeRegistry\V1\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\Client\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\UpdateApiDeploymentRequest; /** * Used to modify a specified deployment. @@ -41,13 +42,15 @@ function update_api_deployment_sample(): void // Create a client. $registryClient = new RegistryClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $apiDeployment = new ApiDeployment(); + $request = (new UpdateApiDeploymentRequest()) + ->setApiDeployment($apiDeployment); // Call the API and handle any network failures. try { /** @var ApiDeployment $response */ - $response = $registryClient->updateApiDeployment($apiDeployment); + $response = $registryClient->updateApiDeployment($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ApigeeRegistry/samples/V1/RegistryClient/update_api_spec.php b/ApigeeRegistry/samples/V1/RegistryClient/update_api_spec.php index a106f9e7d909..8a04c3990d4a 100644 --- a/ApigeeRegistry/samples/V1/RegistryClient/update_api_spec.php +++ b/ApigeeRegistry/samples/V1/RegistryClient/update_api_spec.php @@ -25,7 +25,8 @@ // [START apigeeregistry_v1_generated_Registry_UpdateApiSpec_sync] use Google\ApiCore\ApiException; use Google\Cloud\ApigeeRegistry\V1\ApiSpec; -use Google\Cloud\ApigeeRegistry\V1\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\Client\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\UpdateApiSpecRequest; /** * Used to modify a specified spec. @@ -41,13 +42,15 @@ function update_api_spec_sample(): void // Create a client. $registryClient = new RegistryClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $apiSpec = new ApiSpec(); + $request = (new UpdateApiSpecRequest()) + ->setApiSpec($apiSpec); // Call the API and handle any network failures. try { /** @var ApiSpec $response */ - $response = $registryClient->updateApiSpec($apiSpec); + $response = $registryClient->updateApiSpec($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ApigeeRegistry/samples/V1/RegistryClient/update_api_version.php b/ApigeeRegistry/samples/V1/RegistryClient/update_api_version.php index 6daafdd86e50..a44567378ec6 100644 --- a/ApigeeRegistry/samples/V1/RegistryClient/update_api_version.php +++ b/ApigeeRegistry/samples/V1/RegistryClient/update_api_version.php @@ -25,7 +25,8 @@ // [START apigeeregistry_v1_generated_Registry_UpdateApiVersion_sync] use Google\ApiCore\ApiException; use Google\Cloud\ApigeeRegistry\V1\ApiVersion; -use Google\Cloud\ApigeeRegistry\V1\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\Client\RegistryClient; +use Google\Cloud\ApigeeRegistry\V1\UpdateApiVersionRequest; /** * Used to modify a specified version. @@ -41,13 +42,15 @@ function update_api_version_sample(): void // Create a client. $registryClient = new RegistryClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $apiVersion = new ApiVersion(); + $request = (new UpdateApiVersionRequest()) + ->setApiVersion($apiVersion); // Call the API and handle any network failures. try { /** @var ApiVersion $response */ - $response = $registryClient->updateApiVersion($apiVersion); + $response = $registryClient->updateApiVersion($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ApigeeRegistry/src/V1/Client/BaseClient/ProvisioningBaseClient.php b/ApigeeRegistry/src/V1/Client/BaseClient/ProvisioningBaseClient.php new file mode 100644 index 000000000000..41d311a9c26b --- /dev/null +++ b/ApigeeRegistry/src/V1/Client/BaseClient/ProvisioningBaseClient.php @@ -0,0 +1,487 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/provisioning_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/provisioning_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/provisioning_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/provisioning_rest_client_config.php', + ], + ], + ]; + } + + /** + * Return an OperationsClient object with the same endpoint as $this. + * + * @return OperationsClient + */ + public function getOperationsClient() + { + return $this->operationsClient; + } + + /** + * Resume an existing long running operation that was previously started by a long + * running API method. If $methodName is not provided, or does not match a long + * running API method, then the operation can still be resumed, but the + * OperationResponse object will not deserialize the final response. + * + * @param string $operationName The name of the long running operation + * @param string $methodName The name of the method used to start the operation + * + * @return OperationResponse + */ + public function resumeOperation($operationName, $methodName = null) + { + $options = isset($this->descriptors[$methodName]['longRunning']) ? $this->descriptors[$methodName]['longRunning'] : []; + $operation = new OperationResponse($operationName, $this->getOperationsClient(), $options); + $operation->reload(); + return $operation; + } + + /** + * Formats a string containing the fully-qualified path to represent a instance + * resource. + * + * @param string $project + * @param string $location + * @param string $instance + * + * @return string The formatted instance resource. + */ + public static function instanceName(string $project, string $location, string $instance): string + { + return self::getPathTemplate('instance')->render([ + 'project' => $project, + 'location' => $location, + 'instance' => $instance, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a location + * resource. + * + * @param string $project + * @param string $location + * + * @return string The formatted location resource. + */ + public static function locationName(string $project, string $location): string + { + return self::getPathTemplate('location')->render([ + 'project' => $project, + 'location' => $location, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * Template: Pattern + * - instance: projects/{project}/locations/{location}/instances/{instance} + * - location: projects/{project}/locations/{location} + * + * The optional $template argument can be supplied to specify a particular pattern, + * and must match one of the templates listed above. If no $template argument is + * provided, or if the $template argument does not match one of the templates + * listed, then parseName will check each of the supported templates, and return + * the first match. + * + * @param string $formattedName The formatted name string + * @param string $template Optional name of template to match + * + * @return array An associative array from name component IDs to component values. + * + * @throws ValidationException If $formattedName could not be matched. + */ + public static function parseName(string $formattedName, string $template = null): array + { + return self::parseFormattedName($formattedName, $template); + } + + /** + * Constructor. + * + * @param array $options { + * Optional. Options for configuring the service API wrapper. + * + * @type string $apiEndpoint + * The address of the API remote host. May optionally include the port, formatted + * as ":". Default 'apigeeregistry.googleapis.com:443'. + * @type string|array|FetchAuthTokenInterface|CredentialsWrapper $credentials + * The credentials to be used by the client to authorize API calls. This option + * accepts either a path to a credentials file, or a decoded credentials file as a + * PHP array. + * *Advanced usage*: In addition, this option can also accept a pre-constructed + * {@see \Google\Auth\FetchAuthTokenInterface} object or + * {@see \Google\ApiCore\CredentialsWrapper} object. Note that when one of these + * objects are provided, any settings in $credentialsConfig will be ignored. + * @type array $credentialsConfig + * Options used to configure credentials, including auth token caching, for the + * client. For a full list of supporting configuration options, see + * {@see \Google\ApiCore\CredentialsWrapper::build()} . + * @type bool $disableRetries + * Determines whether or not retries defined by the client configuration should be + * disabled. Defaults to `false`. + * @type string|array $clientConfig + * Client method configuration, including retry settings. This option can be either + * a path to a JSON file, or a PHP array containing the decoded JSON data. By + * default this settings points to the default client config file, which is + * provided in the resources folder. + * @type string|TransportInterface $transport + * The transport used for executing network requests. May be either the string + * `rest` or `grpc`. Defaults to `grpc` if gRPC support is detected on the system. + * *Advanced usage*: Additionally, it is possible to pass in an already + * instantiated {@see \Google\ApiCore\Transport\TransportInterface} object. Note + * that when this object is provided, any settings in $transportConfig, and any + * $apiEndpoint setting, will be ignored. + * @type array $transportConfig + * Configuration options that will be used to construct the transport. Options for + * each supported transport type should be passed in a key for that transport. For + * example: + * $transportConfig = [ + * 'grpc' => [...], + * 'rest' => [...], + * ]; + * See the {@see \Google\ApiCore\Transport\GrpcTransport::build()} and + * {@see \Google\ApiCore\Transport\RestTransport::build()} methods for the + * supported options. + * @type callable $clientCertSource + * A callable which returns the client cert as a string. This can be used to + * provide a certificate and private key to the transport layer for mTLS. + * } + * + * @throws ValidationException + */ + public function __construct(array $options = []) + { + $clientOptions = $this->buildClientOptions($options); + $this->setClientOptions($clientOptions); + $this->operationsClient = $this->createOperationsClient($clientOptions); + } + + /** Handles execution of the async variants for each documented method. */ + public function __call($method, $args) + { + if (substr($method, -5) !== 'Async') { + trigger_error('Call to undefined method ' . __CLASS__ . "::$method()", E_USER_ERROR); + } + + array_unshift($args, substr($method, 0, -5)); + return call_user_func_array([$this, 'startAsyncCall'], $args); + } + + /** + * Provisions instance resources for the Registry. + * + * The async variant is {@see self::createInstanceAsync()} . + * + * @param CreateInstanceRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function createInstance(CreateInstanceRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('CreateInstance', $request, $callOptions)->wait(); + } + + /** + * Deletes the Registry instance. + * + * The async variant is {@see self::deleteInstanceAsync()} . + * + * @param DeleteInstanceRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function deleteInstance(DeleteInstanceRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('DeleteInstance', $request, $callOptions)->wait(); + } + + /** + * Gets details of a single Instance. + * + * The async variant is {@see self::getInstanceAsync()} . + * + * @param GetInstanceRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Instance + * + * @throws ApiException Thrown if the API call fails. + */ + public function getInstance(GetInstanceRequest $request, array $callOptions = []): Instance + { + return $this->startApiCall('GetInstance', $request, $callOptions)->wait(); + } + + /** + * Gets information about a location. + * + * The async variant is {@see self::getLocationAsync()} . + * + * @param GetLocationRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Location + * + * @throws ApiException Thrown if the API call fails. + */ + public function getLocation(GetLocationRequest $request, array $callOptions = []): Location + { + return $this->startApiCall('GetLocation', $request, $callOptions)->wait(); + } + + /** + * Lists information about the supported locations for this service. + * + * The async variant is {@see self::listLocationsAsync()} . + * + * @param ListLocationsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listLocations(ListLocationsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListLocations', $request, $callOptions); + } + + /** + * Gets the access control policy for a resource. Returns an empty policy + if the resource exists and does not have a policy set. + * + * The async variant is {@see self::getIamPolicyAsync()} . + * + * @param GetIamPolicyRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Policy + * + * @throws ApiException Thrown if the API call fails. + */ + public function getIamPolicy(GetIamPolicyRequest $request, array $callOptions = []): Policy + { + return $this->startApiCall('GetIamPolicy', $request, $callOptions)->wait(); + } + + /** + * Sets the access control policy on the specified resource. Replaces + any existing policy. + + Can return `NOT_FOUND`, `INVALID_ARGUMENT`, and `PERMISSION_DENIED` + errors. + * + * The async variant is {@see self::setIamPolicyAsync()} . + * + * @param SetIamPolicyRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Policy + * + * @throws ApiException Thrown if the API call fails. + */ + public function setIamPolicy(SetIamPolicyRequest $request, array $callOptions = []): Policy + { + return $this->startApiCall('SetIamPolicy', $request, $callOptions)->wait(); + } + + /** + * Returns permissions that a caller has on the specified resource. If the + resource does not exist, this will return an empty set of + permissions, not a `NOT_FOUND` error. + + Note: This operation is designed to be used for building + permission-aware UIs and command-line tools, not for authorization + checking. This operation may "fail open" without warning. + * + * The async variant is {@see self::testIamPermissionsAsync()} . + * + * @param TestIamPermissionsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return TestIamPermissionsResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function testIamPermissions(TestIamPermissionsRequest $request, array $callOptions = []): TestIamPermissionsResponse + { + return $this->startApiCall('TestIamPermissions', $request, $callOptions)->wait(); + } +} diff --git a/ApigeeRegistry/src/V1/Client/BaseClient/RegistryBaseClient.php b/ApigeeRegistry/src/V1/Client/BaseClient/RegistryBaseClient.php new file mode 100644 index 000000000000..f7444b064c64 --- /dev/null +++ b/ApigeeRegistry/src/V1/Client/BaseClient/RegistryBaseClient.php @@ -0,0 +1,1497 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/registry_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/registry_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/registry_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/registry_rest_client_config.php', + ], + ], + ]; + } + + /** + * Formats a string containing the fully-qualified path to represent a api + * resource. + * + * @param string $project + * @param string $location + * @param string $api + * + * @return string The formatted api resource. + */ + public static function apiName(string $project, string $location, string $api): string + { + return self::getPathTemplate('api')->render([ + 'project' => $project, + 'location' => $location, + 'api' => $api, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a + * api_deployment resource. + * + * @param string $project + * @param string $location + * @param string $api + * @param string $deployment + * + * @return string The formatted api_deployment resource. + */ + public static function apiDeploymentName(string $project, string $location, string $api, string $deployment): string + { + return self::getPathTemplate('apiDeployment')->render([ + 'project' => $project, + 'location' => $location, + 'api' => $api, + 'deployment' => $deployment, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a api_spec + * resource. + * + * @param string $project + * @param string $location + * @param string $api + * @param string $version + * @param string $spec + * + * @return string The formatted api_spec resource. + */ + public static function apiSpecName(string $project, string $location, string $api, string $version, string $spec): string + { + return self::getPathTemplate('apiSpec')->render([ + 'project' => $project, + 'location' => $location, + 'api' => $api, + 'version' => $version, + 'spec' => $spec, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a api_version + * resource. + * + * @param string $project + * @param string $location + * @param string $api + * @param string $version + * + * @return string The formatted api_version resource. + */ + public static function apiVersionName(string $project, string $location, string $api, string $version): string + { + return self::getPathTemplate('apiVersion')->render([ + 'project' => $project, + 'location' => $location, + 'api' => $api, + 'version' => $version, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a artifact + * resource. + * + * @param string $project + * @param string $location + * @param string $artifact + * + * @return string The formatted artifact resource. + */ + public static function artifactName(string $project, string $location, string $artifact): string + { + return self::getPathTemplate('artifact')->render([ + 'project' => $project, + 'location' => $location, + 'artifact' => $artifact, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a location + * resource. + * + * @param string $project + * @param string $location + * + * @return string The formatted location resource. + */ + public static function locationName(string $project, string $location): string + { + return self::getPathTemplate('location')->render([ + 'project' => $project, + 'location' => $location, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a + * project_location_api_artifact resource. + * + * @param string $project + * @param string $location + * @param string $api + * @param string $artifact + * + * @return string The formatted project_location_api_artifact resource. + */ + public static function projectLocationApiArtifactName(string $project, string $location, string $api, string $artifact): string + { + return self::getPathTemplate('projectLocationApiArtifact')->render([ + 'project' => $project, + 'location' => $location, + 'api' => $api, + 'artifact' => $artifact, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a + * project_location_api_deployment_artifact resource. + * + * @param string $project + * @param string $location + * @param string $api + * @param string $deployment + * @param string $artifact + * + * @return string The formatted project_location_api_deployment_artifact resource. + */ + public static function projectLocationApiDeploymentArtifactName(string $project, string $location, string $api, string $deployment, string $artifact): string + { + return self::getPathTemplate('projectLocationApiDeploymentArtifact')->render([ + 'project' => $project, + 'location' => $location, + 'api' => $api, + 'deployment' => $deployment, + 'artifact' => $artifact, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a + * project_location_api_version_artifact resource. + * + * @param string $project + * @param string $location + * @param string $api + * @param string $version + * @param string $artifact + * + * @return string The formatted project_location_api_version_artifact resource. + */ + public static function projectLocationApiVersionArtifactName(string $project, string $location, string $api, string $version, string $artifact): string + { + return self::getPathTemplate('projectLocationApiVersionArtifact')->render([ + 'project' => $project, + 'location' => $location, + 'api' => $api, + 'version' => $version, + 'artifact' => $artifact, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a + * project_location_api_version_spec_artifact resource. + * + * @param string $project + * @param string $location + * @param string $api + * @param string $version + * @param string $spec + * @param string $artifact + * + * @return string The formatted project_location_api_version_spec_artifact resource. + */ + public static function projectLocationApiVersionSpecArtifactName(string $project, string $location, string $api, string $version, string $spec, string $artifact): string + { + return self::getPathTemplate('projectLocationApiVersionSpecArtifact')->render([ + 'project' => $project, + 'location' => $location, + 'api' => $api, + 'version' => $version, + 'spec' => $spec, + 'artifact' => $artifact, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a + * project_location_artifact resource. + * + * @param string $project + * @param string $location + * @param string $artifact + * + * @return string The formatted project_location_artifact resource. + */ + public static function projectLocationArtifactName(string $project, string $location, string $artifact): string + { + return self::getPathTemplate('projectLocationArtifact')->render([ + 'project' => $project, + 'location' => $location, + 'artifact' => $artifact, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * Template: Pattern + * - api: projects/{project}/locations/{location}/apis/{api} + * - apiDeployment: projects/{project}/locations/{location}/apis/{api}/deployments/{deployment} + * - apiSpec: projects/{project}/locations/{location}/apis/{api}/versions/{version}/specs/{spec} + * - apiVersion: projects/{project}/locations/{location}/apis/{api}/versions/{version} + * - artifact: projects/{project}/locations/{location}/artifacts/{artifact} + * - location: projects/{project}/locations/{location} + * - projectLocationApiArtifact: projects/{project}/locations/{location}/apis/{api}/artifacts/{artifact} + * - projectLocationApiDeploymentArtifact: projects/{project}/locations/{location}/apis/{api}/deployments/{deployment}/artifacts/{artifact} + * - projectLocationApiVersionArtifact: projects/{project}/locations/{location}/apis/{api}/versions/{version}/artifacts/{artifact} + * - projectLocationApiVersionSpecArtifact: projects/{project}/locations/{location}/apis/{api}/versions/{version}/specs/{spec}/artifacts/{artifact} + * - projectLocationArtifact: projects/{project}/locations/{location}/artifacts/{artifact} + * + * The optional $template argument can be supplied to specify a particular pattern, + * and must match one of the templates listed above. If no $template argument is + * provided, or if the $template argument does not match one of the templates + * listed, then parseName will check each of the supported templates, and return + * the first match. + * + * @param string $formattedName The formatted name string + * @param string $template Optional name of template to match + * + * @return array An associative array from name component IDs to component values. + * + * @throws ValidationException If $formattedName could not be matched. + */ + public static function parseName(string $formattedName, string $template = null): array + { + return self::parseFormattedName($formattedName, $template); + } + + /** + * Constructor. + * + * @param array $options { + * Optional. Options for configuring the service API wrapper. + * + * @type string $apiEndpoint + * The address of the API remote host. May optionally include the port, formatted + * as ":". Default 'apigeeregistry.googleapis.com:443'. + * @type string|array|FetchAuthTokenInterface|CredentialsWrapper $credentials + * The credentials to be used by the client to authorize API calls. This option + * accepts either a path to a credentials file, or a decoded credentials file as a + * PHP array. + * *Advanced usage*: In addition, this option can also accept a pre-constructed + * {@see \Google\Auth\FetchAuthTokenInterface} object or + * {@see \Google\ApiCore\CredentialsWrapper} object. Note that when one of these + * objects are provided, any settings in $credentialsConfig will be ignored. + * @type array $credentialsConfig + * Options used to configure credentials, including auth token caching, for the + * client. For a full list of supporting configuration options, see + * {@see \Google\ApiCore\CredentialsWrapper::build()} . + * @type bool $disableRetries + * Determines whether or not retries defined by the client configuration should be + * disabled. Defaults to `false`. + * @type string|array $clientConfig + * Client method configuration, including retry settings. This option can be either + * a path to a JSON file, or a PHP array containing the decoded JSON data. By + * default this settings points to the default client config file, which is + * provided in the resources folder. + * @type string|TransportInterface $transport + * The transport used for executing network requests. May be either the string + * `rest` or `grpc`. Defaults to `grpc` if gRPC support is detected on the system. + * *Advanced usage*: Additionally, it is possible to pass in an already + * instantiated {@see \Google\ApiCore\Transport\TransportInterface} object. Note + * that when this object is provided, any settings in $transportConfig, and any + * $apiEndpoint setting, will be ignored. + * @type array $transportConfig + * Configuration options that will be used to construct the transport. Options for + * each supported transport type should be passed in a key for that transport. For + * example: + * $transportConfig = [ + * 'grpc' => [...], + * 'rest' => [...], + * ]; + * See the {@see \Google\ApiCore\Transport\GrpcTransport::build()} and + * {@see \Google\ApiCore\Transport\RestTransport::build()} methods for the + * supported options. + * @type callable $clientCertSource + * A callable which returns the client cert as a string. This can be used to + * provide a certificate and private key to the transport layer for mTLS. + * } + * + * @throws ValidationException + */ + public function __construct(array $options = []) + { + $clientOptions = $this->buildClientOptions($options); + $this->setClientOptions($clientOptions); + } + + /** Handles execution of the async variants for each documented method. */ + public function __call($method, $args) + { + if (substr($method, -5) !== 'Async') { + trigger_error('Call to undefined method ' . __CLASS__ . "::$method()", E_USER_ERROR); + } + + array_unshift($args, substr($method, 0, -5)); + return call_user_func_array([$this, 'startAsyncCall'], $args); + } + + /** + * Creates a specified API. + * + * The async variant is {@see self::createApiAsync()} . + * + * @param CreateApiRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Api + * + * @throws ApiException Thrown if the API call fails. + */ + public function createApi(CreateApiRequest $request, array $callOptions = []): Api + { + return $this->startApiCall('CreateApi', $request, $callOptions)->wait(); + } + + /** + * Creates a specified deployment. + * + * The async variant is {@see self::createApiDeploymentAsync()} . + * + * @param CreateApiDeploymentRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return ApiDeployment + * + * @throws ApiException Thrown if the API call fails. + */ + public function createApiDeployment(CreateApiDeploymentRequest $request, array $callOptions = []): ApiDeployment + { + return $this->startApiCall('CreateApiDeployment', $request, $callOptions)->wait(); + } + + /** + * Creates a specified spec. + * + * The async variant is {@see self::createApiSpecAsync()} . + * + * @param CreateApiSpecRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return ApiSpec + * + * @throws ApiException Thrown if the API call fails. + */ + public function createApiSpec(CreateApiSpecRequest $request, array $callOptions = []): ApiSpec + { + return $this->startApiCall('CreateApiSpec', $request, $callOptions)->wait(); + } + + /** + * Creates a specified version. + * + * The async variant is {@see self::createApiVersionAsync()} . + * + * @param CreateApiVersionRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return ApiVersion + * + * @throws ApiException Thrown if the API call fails. + */ + public function createApiVersion(CreateApiVersionRequest $request, array $callOptions = []): ApiVersion + { + return $this->startApiCall('CreateApiVersion', $request, $callOptions)->wait(); + } + + /** + * Creates a specified artifact. + * + * The async variant is {@see self::createArtifactAsync()} . + * + * @param CreateArtifactRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Artifact + * + * @throws ApiException Thrown if the API call fails. + */ + public function createArtifact(CreateArtifactRequest $request, array $callOptions = []): Artifact + { + return $this->startApiCall('CreateArtifact', $request, $callOptions)->wait(); + } + + /** + * Removes a specified API and all of the resources that it + * owns. + * + * The async variant is {@see self::deleteApiAsync()} . + * + * @param DeleteApiRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @throws ApiException Thrown if the API call fails. + */ + public function deleteApi(DeleteApiRequest $request, array $callOptions = []): void + { + $this->startApiCall('DeleteApi', $request, $callOptions)->wait(); + } + + /** + * Removes a specified deployment, all revisions, and all + * child resources (e.g., artifacts). + * + * The async variant is {@see self::deleteApiDeploymentAsync()} . + * + * @param DeleteApiDeploymentRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @throws ApiException Thrown if the API call fails. + */ + public function deleteApiDeployment(DeleteApiDeploymentRequest $request, array $callOptions = []): void + { + $this->startApiCall('DeleteApiDeployment', $request, $callOptions)->wait(); + } + + /** + * Deletes a revision of a deployment. + * + * The async variant is {@see self::deleteApiDeploymentRevisionAsync()} . + * + * @param DeleteApiDeploymentRevisionRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return ApiDeployment + * + * @throws ApiException Thrown if the API call fails. + */ + public function deleteApiDeploymentRevision(DeleteApiDeploymentRevisionRequest $request, array $callOptions = []): ApiDeployment + { + return $this->startApiCall('DeleteApiDeploymentRevision', $request, $callOptions)->wait(); + } + + /** + * Removes a specified spec, all revisions, and all child + * resources (e.g., artifacts). + * + * The async variant is {@see self::deleteApiSpecAsync()} . + * + * @param DeleteApiSpecRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @throws ApiException Thrown if the API call fails. + */ + public function deleteApiSpec(DeleteApiSpecRequest $request, array $callOptions = []): void + { + $this->startApiCall('DeleteApiSpec', $request, $callOptions)->wait(); + } + + /** + * Deletes a revision of a spec. + * + * The async variant is {@see self::deleteApiSpecRevisionAsync()} . + * + * @param DeleteApiSpecRevisionRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return ApiSpec + * + * @throws ApiException Thrown if the API call fails. + */ + public function deleteApiSpecRevision(DeleteApiSpecRevisionRequest $request, array $callOptions = []): ApiSpec + { + return $this->startApiCall('DeleteApiSpecRevision', $request, $callOptions)->wait(); + } + + /** + * Removes a specified version and all of the resources that + * it owns. + * + * The async variant is {@see self::deleteApiVersionAsync()} . + * + * @param DeleteApiVersionRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @throws ApiException Thrown if the API call fails. + */ + public function deleteApiVersion(DeleteApiVersionRequest $request, array $callOptions = []): void + { + $this->startApiCall('DeleteApiVersion', $request, $callOptions)->wait(); + } + + /** + * Removes a specified artifact. + * + * The async variant is {@see self::deleteArtifactAsync()} . + * + * @param DeleteArtifactRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @throws ApiException Thrown if the API call fails. + */ + public function deleteArtifact(DeleteArtifactRequest $request, array $callOptions = []): void + { + $this->startApiCall('DeleteArtifact', $request, $callOptions)->wait(); + } + + /** + * Returns a specified API. + * + * The async variant is {@see self::getApiAsync()} . + * + * @param GetApiRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Api + * + * @throws ApiException Thrown if the API call fails. + */ + public function getApi(GetApiRequest $request, array $callOptions = []): Api + { + return $this->startApiCall('GetApi', $request, $callOptions)->wait(); + } + + /** + * Returns a specified deployment. + * + * The async variant is {@see self::getApiDeploymentAsync()} . + * + * @param GetApiDeploymentRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return ApiDeployment + * + * @throws ApiException Thrown if the API call fails. + */ + public function getApiDeployment(GetApiDeploymentRequest $request, array $callOptions = []): ApiDeployment + { + return $this->startApiCall('GetApiDeployment', $request, $callOptions)->wait(); + } + + /** + * Returns a specified spec. + * + * The async variant is {@see self::getApiSpecAsync()} . + * + * @param GetApiSpecRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return ApiSpec + * + * @throws ApiException Thrown if the API call fails. + */ + public function getApiSpec(GetApiSpecRequest $request, array $callOptions = []): ApiSpec + { + return $this->startApiCall('GetApiSpec', $request, $callOptions)->wait(); + } + + /** + * Returns the contents of a specified spec. + * If specs are stored with GZip compression, the default behavior + * is to return the spec uncompressed (the mime_type response field + * indicates the exact format returned). + * + * The async variant is {@see self::getApiSpecContentsAsync()} . + * + * @param GetApiSpecContentsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return HttpBody + * + * @throws ApiException Thrown if the API call fails. + */ + public function getApiSpecContents(GetApiSpecContentsRequest $request, array $callOptions = []): HttpBody + { + return $this->startApiCall('GetApiSpecContents', $request, $callOptions)->wait(); + } + + /** + * Returns a specified version. + * + * The async variant is {@see self::getApiVersionAsync()} . + * + * @param GetApiVersionRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return ApiVersion + * + * @throws ApiException Thrown if the API call fails. + */ + public function getApiVersion(GetApiVersionRequest $request, array $callOptions = []): ApiVersion + { + return $this->startApiCall('GetApiVersion', $request, $callOptions)->wait(); + } + + /** + * Returns a specified artifact. + * + * The async variant is {@see self::getArtifactAsync()} . + * + * @param GetArtifactRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Artifact + * + * @throws ApiException Thrown if the API call fails. + */ + public function getArtifact(GetArtifactRequest $request, array $callOptions = []): Artifact + { + return $this->startApiCall('GetArtifact', $request, $callOptions)->wait(); + } + + /** + * Returns the contents of a specified artifact. + * If artifacts are stored with GZip compression, the default behavior + * is to return the artifact uncompressed (the mime_type response field + * indicates the exact format returned). + * + * The async variant is {@see self::getArtifactContentsAsync()} . + * + * @param GetArtifactContentsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return HttpBody + * + * @throws ApiException Thrown if the API call fails. + */ + public function getArtifactContents(GetArtifactContentsRequest $request, array $callOptions = []): HttpBody + { + return $this->startApiCall('GetArtifactContents', $request, $callOptions)->wait(); + } + + /** + * Lists all revisions of a deployment. + * Revisions are returned in descending order of revision creation time. + * + * The async variant is {@see self::listApiDeploymentRevisionsAsync()} . + * + * @param ListApiDeploymentRevisionsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listApiDeploymentRevisions(ListApiDeploymentRevisionsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListApiDeploymentRevisions', $request, $callOptions); + } + + /** + * Returns matching deployments. + * + * The async variant is {@see self::listApiDeploymentsAsync()} . + * + * @param ListApiDeploymentsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listApiDeployments(ListApiDeploymentsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListApiDeployments', $request, $callOptions); + } + + /** + * Lists all revisions of a spec. + * Revisions are returned in descending order of revision creation time. + * + * The async variant is {@see self::listApiSpecRevisionsAsync()} . + * + * @param ListApiSpecRevisionsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listApiSpecRevisions(ListApiSpecRevisionsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListApiSpecRevisions', $request, $callOptions); + } + + /** + * Returns matching specs. + * + * The async variant is {@see self::listApiSpecsAsync()} . + * + * @param ListApiSpecsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listApiSpecs(ListApiSpecsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListApiSpecs', $request, $callOptions); + } + + /** + * Returns matching versions. + * + * The async variant is {@see self::listApiVersionsAsync()} . + * + * @param ListApiVersionsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listApiVersions(ListApiVersionsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListApiVersions', $request, $callOptions); + } + + /** + * Returns matching APIs. + * + * The async variant is {@see self::listApisAsync()} . + * + * @param ListApisRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listApis(ListApisRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListApis', $request, $callOptions); + } + + /** + * Returns matching artifacts. + * + * The async variant is {@see self::listArtifactsAsync()} . + * + * @param ListArtifactsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listArtifacts(ListArtifactsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListArtifacts', $request, $callOptions); + } + + /** + * Used to replace a specified artifact. + * + * The async variant is {@see self::replaceArtifactAsync()} . + * + * @param ReplaceArtifactRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Artifact + * + * @throws ApiException Thrown if the API call fails. + */ + public function replaceArtifact(ReplaceArtifactRequest $request, array $callOptions = []): Artifact + { + return $this->startApiCall('ReplaceArtifact', $request, $callOptions)->wait(); + } + + /** + * Sets the current revision to a specified prior + * revision. Note that this creates a new revision with a new revision ID. + * + * The async variant is {@see self::rollbackApiDeploymentAsync()} . + * + * @param RollbackApiDeploymentRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return ApiDeployment + * + * @throws ApiException Thrown if the API call fails. + */ + public function rollbackApiDeployment(RollbackApiDeploymentRequest $request, array $callOptions = []): ApiDeployment + { + return $this->startApiCall('RollbackApiDeployment', $request, $callOptions)->wait(); + } + + /** + * Sets the current revision to a specified prior revision. + * Note that this creates a new revision with a new revision ID. + * + * The async variant is {@see self::rollbackApiSpecAsync()} . + * + * @param RollbackApiSpecRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return ApiSpec + * + * @throws ApiException Thrown if the API call fails. + */ + public function rollbackApiSpec(RollbackApiSpecRequest $request, array $callOptions = []): ApiSpec + { + return $this->startApiCall('RollbackApiSpec', $request, $callOptions)->wait(); + } + + /** + * Adds a tag to a specified revision of a + * deployment. + * + * The async variant is {@see self::tagApiDeploymentRevisionAsync()} . + * + * @param TagApiDeploymentRevisionRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return ApiDeployment + * + * @throws ApiException Thrown if the API call fails. + */ + public function tagApiDeploymentRevision(TagApiDeploymentRevisionRequest $request, array $callOptions = []): ApiDeployment + { + return $this->startApiCall('TagApiDeploymentRevision', $request, $callOptions)->wait(); + } + + /** + * Adds a tag to a specified revision of a spec. + * + * The async variant is {@see self::tagApiSpecRevisionAsync()} . + * + * @param TagApiSpecRevisionRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return ApiSpec + * + * @throws ApiException Thrown if the API call fails. + */ + public function tagApiSpecRevision(TagApiSpecRevisionRequest $request, array $callOptions = []): ApiSpec + { + return $this->startApiCall('TagApiSpecRevision', $request, $callOptions)->wait(); + } + + /** + * Used to modify a specified API. + * + * The async variant is {@see self::updateApiAsync()} . + * + * @param UpdateApiRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Api + * + * @throws ApiException Thrown if the API call fails. + */ + public function updateApi(UpdateApiRequest $request, array $callOptions = []): Api + { + return $this->startApiCall('UpdateApi', $request, $callOptions)->wait(); + } + + /** + * Used to modify a specified deployment. + * + * The async variant is {@see self::updateApiDeploymentAsync()} . + * + * @param UpdateApiDeploymentRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return ApiDeployment + * + * @throws ApiException Thrown if the API call fails. + */ + public function updateApiDeployment(UpdateApiDeploymentRequest $request, array $callOptions = []): ApiDeployment + { + return $this->startApiCall('UpdateApiDeployment', $request, $callOptions)->wait(); + } + + /** + * Used to modify a specified spec. + * + * The async variant is {@see self::updateApiSpecAsync()} . + * + * @param UpdateApiSpecRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return ApiSpec + * + * @throws ApiException Thrown if the API call fails. + */ + public function updateApiSpec(UpdateApiSpecRequest $request, array $callOptions = []): ApiSpec + { + return $this->startApiCall('UpdateApiSpec', $request, $callOptions)->wait(); + } + + /** + * Used to modify a specified version. + * + * The async variant is {@see self::updateApiVersionAsync()} . + * + * @param UpdateApiVersionRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return ApiVersion + * + * @throws ApiException Thrown if the API call fails. + */ + public function updateApiVersion(UpdateApiVersionRequest $request, array $callOptions = []): ApiVersion + { + return $this->startApiCall('UpdateApiVersion', $request, $callOptions)->wait(); + } + + /** + * Gets information about a location. + * + * The async variant is {@see self::getLocationAsync()} . + * + * @param GetLocationRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Location + * + * @throws ApiException Thrown if the API call fails. + */ + public function getLocation(GetLocationRequest $request, array $callOptions = []): Location + { + return $this->startApiCall('GetLocation', $request, $callOptions)->wait(); + } + + /** + * Lists information about the supported locations for this service. + * + * The async variant is {@see self::listLocationsAsync()} . + * + * @param ListLocationsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listLocations(ListLocationsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListLocations', $request, $callOptions); + } + + /** + * Gets the access control policy for a resource. Returns an empty policy + if the resource exists and does not have a policy set. + * + * The async variant is {@see self::getIamPolicyAsync()} . + * + * @param GetIamPolicyRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Policy + * + * @throws ApiException Thrown if the API call fails. + */ + public function getIamPolicy(GetIamPolicyRequest $request, array $callOptions = []): Policy + { + return $this->startApiCall('GetIamPolicy', $request, $callOptions)->wait(); + } + + /** + * Sets the access control policy on the specified resource. Replaces + any existing policy. + + Can return `NOT_FOUND`, `INVALID_ARGUMENT`, and `PERMISSION_DENIED` + errors. + * + * The async variant is {@see self::setIamPolicyAsync()} . + * + * @param SetIamPolicyRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Policy + * + * @throws ApiException Thrown if the API call fails. + */ + public function setIamPolicy(SetIamPolicyRequest $request, array $callOptions = []): Policy + { + return $this->startApiCall('SetIamPolicy', $request, $callOptions)->wait(); + } + + /** + * Returns permissions that a caller has on the specified resource. If the + resource does not exist, this will return an empty set of + permissions, not a `NOT_FOUND` error. + + Note: This operation is designed to be used for building + permission-aware UIs and command-line tools, not for authorization + checking. This operation may "fail open" without warning. + * + * The async variant is {@see self::testIamPermissionsAsync()} . + * + * @param TestIamPermissionsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return TestIamPermissionsResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function testIamPermissions(TestIamPermissionsRequest $request, array $callOptions = []): TestIamPermissionsResponse + { + return $this->startApiCall('TestIamPermissions', $request, $callOptions)->wait(); + } +} diff --git a/ApigeeRegistry/src/V1/Client/ProvisioningClient.php b/ApigeeRegistry/src/V1/Client/ProvisioningClient.php new file mode 100644 index 000000000000..55602827834e --- /dev/null +++ b/ApigeeRegistry/src/V1/Client/ProvisioningClient.php @@ -0,0 +1,40 @@ +setParent($parent) + ->setApiDeployment($apiDeployment) + ->setApiDeploymentId($apiDeploymentId); + } + /** * Constructor. * diff --git a/ApigeeRegistry/src/V1/CreateApiRequest.php b/ApigeeRegistry/src/V1/CreateApiRequest.php index 34aa4078f26d..7ae6f6d728f0 100644 --- a/ApigeeRegistry/src/V1/CreateApiRequest.php +++ b/ApigeeRegistry/src/V1/CreateApiRequest.php @@ -39,6 +39,31 @@ class CreateApiRequest extends \Google\Protobuf\Internal\Message */ private $api_id = ''; + /** + * @param string $parent Required. The parent, which owns this collection of APIs. + * Format: `projects/*/locations/*` + * Please see {@see RegistryClient::locationName()} for help formatting this field. + * @param \Google\Cloud\ApigeeRegistry\V1\Api $api Required. The API to create. + * @param string $apiId Required. The ID to use for the API, which will become the final component of + * the API's resource name. + * + * This value should be 4-63 characters, and valid characters + * are /[a-z][0-9]-/. + * + * Following AIP-162, IDs must not have the form of a UUID. + * + * @return \Google\Cloud\ApigeeRegistry\V1\CreateApiRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\ApigeeRegistry\V1\Api $api, string $apiId): self + { + return (new self()) + ->setParent($parent) + ->setApi($api) + ->setApiId($apiId); + } + /** * Constructor. * diff --git a/ApigeeRegistry/src/V1/CreateApiSpecRequest.php b/ApigeeRegistry/src/V1/CreateApiSpecRequest.php index cab89587448c..d8c7805110ff 100644 --- a/ApigeeRegistry/src/V1/CreateApiSpecRequest.php +++ b/ApigeeRegistry/src/V1/CreateApiSpecRequest.php @@ -39,6 +39,31 @@ class CreateApiSpecRequest extends \Google\Protobuf\Internal\Message */ private $api_spec_id = ''; + /** + * @param string $parent Required. The parent, which owns this collection of specs. + * Format: `projects/*/locations/*/apis/*/versions/*` + * Please see {@see RegistryClient::apiVersionName()} for help formatting this field. + * @param \Google\Cloud\ApigeeRegistry\V1\ApiSpec $apiSpec Required. The spec to create. + * @param string $apiSpecId Required. The ID to use for the spec, which will become the final component of + * the spec's resource name. + * + * This value should be 4-63 characters, and valid characters + * are /[a-z][0-9]-/. + * + * Following AIP-162, IDs must not have the form of a UUID. + * + * @return \Google\Cloud\ApigeeRegistry\V1\CreateApiSpecRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\ApigeeRegistry\V1\ApiSpec $apiSpec, string $apiSpecId): self + { + return (new self()) + ->setParent($parent) + ->setApiSpec($apiSpec) + ->setApiSpecId($apiSpecId); + } + /** * Constructor. * diff --git a/ApigeeRegistry/src/V1/CreateApiVersionRequest.php b/ApigeeRegistry/src/V1/CreateApiVersionRequest.php index b4253766319f..7deff8dea680 100644 --- a/ApigeeRegistry/src/V1/CreateApiVersionRequest.php +++ b/ApigeeRegistry/src/V1/CreateApiVersionRequest.php @@ -39,6 +39,31 @@ class CreateApiVersionRequest extends \Google\Protobuf\Internal\Message */ private $api_version_id = ''; + /** + * @param string $parent Required. The parent, which owns this collection of versions. + * Format: `projects/*/locations/*/apis/*` + * Please see {@see RegistryClient::apiName()} for help formatting this field. + * @param \Google\Cloud\ApigeeRegistry\V1\ApiVersion $apiVersion Required. The version to create. + * @param string $apiVersionId Required. The ID to use for the version, which will become the final component of + * the version's resource name. + * + * This value should be 1-63 characters, and valid characters + * are /[a-z][0-9]-/. + * + * Following AIP-162, IDs must not have the form of a UUID. + * + * @return \Google\Cloud\ApigeeRegistry\V1\CreateApiVersionRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\ApigeeRegistry\V1\ApiVersion $apiVersion, string $apiVersionId): self + { + return (new self()) + ->setParent($parent) + ->setApiVersion($apiVersion) + ->setApiVersionId($apiVersionId); + } + /** * Constructor. * diff --git a/ApigeeRegistry/src/V1/CreateArtifactRequest.php b/ApigeeRegistry/src/V1/CreateArtifactRequest.php index 8c83a63f7f0d..57372d98b2c6 100644 --- a/ApigeeRegistry/src/V1/CreateArtifactRequest.php +++ b/ApigeeRegistry/src/V1/CreateArtifactRequest.php @@ -39,6 +39,31 @@ class CreateArtifactRequest extends \Google\Protobuf\Internal\Message */ private $artifact_id = ''; + /** + * @param string $parent Required. The parent, which owns this collection of artifacts. + * Format: `{parent}` + * Please see {@see RegistryClient::locationName()} for help formatting this field. + * @param \Google\Cloud\ApigeeRegistry\V1\Artifact $artifact Required. The artifact to create. + * @param string $artifactId Required. The ID to use for the artifact, which will become the final component of + * the artifact's resource name. + * + * This value should be 4-63 characters, and valid characters + * are /[a-z][0-9]-/. + * + * Following AIP-162, IDs must not have the form of a UUID. + * + * @return \Google\Cloud\ApigeeRegistry\V1\CreateArtifactRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\ApigeeRegistry\V1\Artifact $artifact, string $artifactId): self + { + return (new self()) + ->setParent($parent) + ->setArtifact($artifact) + ->setArtifactId($artifactId); + } + /** * Constructor. * diff --git a/ApigeeRegistry/src/V1/CreateInstanceRequest.php b/ApigeeRegistry/src/V1/CreateInstanceRequest.php index 0ebc4cb3372b..e095425853a6 100644 --- a/ApigeeRegistry/src/V1/CreateInstanceRequest.php +++ b/ApigeeRegistry/src/V1/CreateInstanceRequest.php @@ -35,6 +35,25 @@ class CreateInstanceRequest extends \Google\Protobuf\Internal\Message */ private $instance = null; + /** + * @param string $parent Required. Parent resource of the Instance, of the form: `projects/*/locations/*` + * Please see {@see ProvisioningClient::locationName()} for help formatting this field. + * @param \Google\Cloud\ApigeeRegistry\V1\Instance $instance Required. The Instance. + * @param string $instanceId Required. Identifier to assign to the Instance. Must be unique within scope of the + * parent resource. + * + * @return \Google\Cloud\ApigeeRegistry\V1\CreateInstanceRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\ApigeeRegistry\V1\Instance $instance, string $instanceId): self + { + return (new self()) + ->setParent($parent) + ->setInstance($instance) + ->setInstanceId($instanceId); + } + /** * Constructor. * diff --git a/ApigeeRegistry/src/V1/DeleteApiDeploymentRequest.php b/ApigeeRegistry/src/V1/DeleteApiDeploymentRequest.php index ebb040f9121a..be3d27470300 100644 --- a/ApigeeRegistry/src/V1/DeleteApiDeploymentRequest.php +++ b/ApigeeRegistry/src/V1/DeleteApiDeploymentRequest.php @@ -30,6 +30,21 @@ class DeleteApiDeploymentRequest extends \Google\Protobuf\Internal\Message */ private $force = false; + /** + * @param string $name Required. The name of the deployment to delete. + * Format: `projects/*/locations/*/apis/*/deployments/*` + * Please see {@see RegistryClient::apiDeploymentName()} for help formatting this field. + * + * @return \Google\Cloud\ApigeeRegistry\V1\DeleteApiDeploymentRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/ApigeeRegistry/src/V1/DeleteApiDeploymentRevisionRequest.php b/ApigeeRegistry/src/V1/DeleteApiDeploymentRevisionRequest.php index c3fa13e7611b..197567f7b17c 100644 --- a/ApigeeRegistry/src/V1/DeleteApiDeploymentRevisionRequest.php +++ b/ApigeeRegistry/src/V1/DeleteApiDeploymentRevisionRequest.php @@ -25,6 +25,24 @@ class DeleteApiDeploymentRevisionRequest extends \Google\Protobuf\Internal\Messa */ private $name = ''; + /** + * @param string $name Required. The name of the deployment revision to be deleted, + * with a revision ID explicitly included. + * + * Example: + * `projects/sample/locations/global/apis/petstore/deployments/prod@c7cfa2a8` + * Please see {@see RegistryClient::apiDeploymentName()} for help formatting this field. + * + * @return \Google\Cloud\ApigeeRegistry\V1\DeleteApiDeploymentRevisionRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/ApigeeRegistry/src/V1/DeleteApiRequest.php b/ApigeeRegistry/src/V1/DeleteApiRequest.php index 65ff1d99bc67..fccfa8ab6a1a 100644 --- a/ApigeeRegistry/src/V1/DeleteApiRequest.php +++ b/ApigeeRegistry/src/V1/DeleteApiRequest.php @@ -30,6 +30,21 @@ class DeleteApiRequest extends \Google\Protobuf\Internal\Message */ private $force = false; + /** + * @param string $name Required. The name of the API to delete. + * Format: `projects/*/locations/*/apis/*` + * Please see {@see RegistryClient::apiName()} for help formatting this field. + * + * @return \Google\Cloud\ApigeeRegistry\V1\DeleteApiRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/ApigeeRegistry/src/V1/DeleteApiSpecRequest.php b/ApigeeRegistry/src/V1/DeleteApiSpecRequest.php index 92a0d83f8ffd..cb88e6a266f7 100644 --- a/ApigeeRegistry/src/V1/DeleteApiSpecRequest.php +++ b/ApigeeRegistry/src/V1/DeleteApiSpecRequest.php @@ -30,6 +30,21 @@ class DeleteApiSpecRequest extends \Google\Protobuf\Internal\Message */ private $force = false; + /** + * @param string $name Required. The name of the spec to delete. + * Format: `projects/*/locations/*/apis/*/versions/*/specs/*` + * Please see {@see RegistryClient::apiSpecName()} for help formatting this field. + * + * @return \Google\Cloud\ApigeeRegistry\V1\DeleteApiSpecRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/ApigeeRegistry/src/V1/DeleteApiSpecRevisionRequest.php b/ApigeeRegistry/src/V1/DeleteApiSpecRevisionRequest.php index 0e0a87a5287c..adba6faae0fe 100644 --- a/ApigeeRegistry/src/V1/DeleteApiSpecRevisionRequest.php +++ b/ApigeeRegistry/src/V1/DeleteApiSpecRevisionRequest.php @@ -25,6 +25,24 @@ class DeleteApiSpecRevisionRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The name of the spec revision to be deleted, + * with a revision ID explicitly included. + * + * Example: + * `projects/sample/locations/global/apis/petstore/versions/1.0.0/specs/openapi.yaml@c7cfa2a8` + * Please see {@see RegistryClient::apiSpecName()} for help formatting this field. + * + * @return \Google\Cloud\ApigeeRegistry\V1\DeleteApiSpecRevisionRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/ApigeeRegistry/src/V1/DeleteApiVersionRequest.php b/ApigeeRegistry/src/V1/DeleteApiVersionRequest.php index a217ebd1d9de..a87667a58a66 100644 --- a/ApigeeRegistry/src/V1/DeleteApiVersionRequest.php +++ b/ApigeeRegistry/src/V1/DeleteApiVersionRequest.php @@ -30,6 +30,21 @@ class DeleteApiVersionRequest extends \Google\Protobuf\Internal\Message */ private $force = false; + /** + * @param string $name Required. The name of the version to delete. + * Format: `projects/*/locations/*/apis/*/versions/*` + * Please see {@see RegistryClient::apiVersionName()} for help formatting this field. + * + * @return \Google\Cloud\ApigeeRegistry\V1\DeleteApiVersionRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/ApigeeRegistry/src/V1/DeleteArtifactRequest.php b/ApigeeRegistry/src/V1/DeleteArtifactRequest.php index 49372d74c175..cf648f27b1cd 100644 --- a/ApigeeRegistry/src/V1/DeleteArtifactRequest.php +++ b/ApigeeRegistry/src/V1/DeleteArtifactRequest.php @@ -23,6 +23,21 @@ class DeleteArtifactRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The name of the artifact to delete. + * Format: `{parent}/artifacts/*` + * Please see {@see RegistryClient::artifactName()} for help formatting this field. + * + * @return \Google\Cloud\ApigeeRegistry\V1\DeleteArtifactRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/ApigeeRegistry/src/V1/DeleteInstanceRequest.php b/ApigeeRegistry/src/V1/DeleteInstanceRequest.php index 7072b4b123cf..abba565a0950 100644 --- a/ApigeeRegistry/src/V1/DeleteInstanceRequest.php +++ b/ApigeeRegistry/src/V1/DeleteInstanceRequest.php @@ -23,6 +23,21 @@ class DeleteInstanceRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The name of the Instance to delete. + * Format: `projects/*/locations/*/instances/*`. Please see + * {@see ProvisioningClient::instanceName()} for help formatting this field. + * + * @return \Google\Cloud\ApigeeRegistry\V1\DeleteInstanceRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/ApigeeRegistry/src/V1/GetApiDeploymentRequest.php b/ApigeeRegistry/src/V1/GetApiDeploymentRequest.php index a58117005ea7..afe276b578b2 100644 --- a/ApigeeRegistry/src/V1/GetApiDeploymentRequest.php +++ b/ApigeeRegistry/src/V1/GetApiDeploymentRequest.php @@ -23,6 +23,21 @@ class GetApiDeploymentRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The name of the deployment to retrieve. + * Format: `projects/*/locations/*/apis/*/deployments/*` + * Please see {@see RegistryClient::apiDeploymentName()} for help formatting this field. + * + * @return \Google\Cloud\ApigeeRegistry\V1\GetApiDeploymentRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/ApigeeRegistry/src/V1/GetApiRequest.php b/ApigeeRegistry/src/V1/GetApiRequest.php index 54c8ac14a988..facc07c7d402 100644 --- a/ApigeeRegistry/src/V1/GetApiRequest.php +++ b/ApigeeRegistry/src/V1/GetApiRequest.php @@ -23,6 +23,21 @@ class GetApiRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The name of the API to retrieve. + * Format: `projects/*/locations/*/apis/*` + * Please see {@see RegistryClient::apiName()} for help formatting this field. + * + * @return \Google\Cloud\ApigeeRegistry\V1\GetApiRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/ApigeeRegistry/src/V1/GetApiSpecContentsRequest.php b/ApigeeRegistry/src/V1/GetApiSpecContentsRequest.php index c9f9c03e9a60..5e24fda3b988 100644 --- a/ApigeeRegistry/src/V1/GetApiSpecContentsRequest.php +++ b/ApigeeRegistry/src/V1/GetApiSpecContentsRequest.php @@ -23,6 +23,21 @@ class GetApiSpecContentsRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The name of the spec whose contents should be retrieved. + * Format: `projects/*/locations/*/apis/*/versions/*/specs/*` + * Please see {@see RegistryClient::apiSpecName()} for help formatting this field. + * + * @return \Google\Cloud\ApigeeRegistry\V1\GetApiSpecContentsRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/ApigeeRegistry/src/V1/GetApiSpecRequest.php b/ApigeeRegistry/src/V1/GetApiSpecRequest.php index b1b9f9eec4c2..b9d2541192e7 100644 --- a/ApigeeRegistry/src/V1/GetApiSpecRequest.php +++ b/ApigeeRegistry/src/V1/GetApiSpecRequest.php @@ -23,6 +23,21 @@ class GetApiSpecRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The name of the spec to retrieve. + * Format: `projects/*/locations/*/apis/*/versions/*/specs/*` + * Please see {@see RegistryClient::apiSpecName()} for help formatting this field. + * + * @return \Google\Cloud\ApigeeRegistry\V1\GetApiSpecRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/ApigeeRegistry/src/V1/GetApiVersionRequest.php b/ApigeeRegistry/src/V1/GetApiVersionRequest.php index d7debc11b908..a3e9d8f9154b 100644 --- a/ApigeeRegistry/src/V1/GetApiVersionRequest.php +++ b/ApigeeRegistry/src/V1/GetApiVersionRequest.php @@ -23,6 +23,21 @@ class GetApiVersionRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The name of the version to retrieve. + * Format: `projects/*/locations/*/apis/*/versions/*` + * Please see {@see RegistryClient::apiVersionName()} for help formatting this field. + * + * @return \Google\Cloud\ApigeeRegistry\V1\GetApiVersionRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/ApigeeRegistry/src/V1/GetArtifactContentsRequest.php b/ApigeeRegistry/src/V1/GetArtifactContentsRequest.php index b81e4e69b6f3..dae16de3de84 100644 --- a/ApigeeRegistry/src/V1/GetArtifactContentsRequest.php +++ b/ApigeeRegistry/src/V1/GetArtifactContentsRequest.php @@ -23,6 +23,21 @@ class GetArtifactContentsRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The name of the artifact whose contents should be retrieved. + * Format: `{parent}/artifacts/*` + * Please see {@see RegistryClient::artifactName()} for help formatting this field. + * + * @return \Google\Cloud\ApigeeRegistry\V1\GetArtifactContentsRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/ApigeeRegistry/src/V1/GetArtifactRequest.php b/ApigeeRegistry/src/V1/GetArtifactRequest.php index be9ee8e46d03..d6a4d90817c3 100644 --- a/ApigeeRegistry/src/V1/GetArtifactRequest.php +++ b/ApigeeRegistry/src/V1/GetArtifactRequest.php @@ -23,6 +23,21 @@ class GetArtifactRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The name of the artifact to retrieve. + * Format: `{parent}/artifacts/*` + * Please see {@see RegistryClient::artifactName()} for help formatting this field. + * + * @return \Google\Cloud\ApigeeRegistry\V1\GetArtifactRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/ApigeeRegistry/src/V1/GetInstanceRequest.php b/ApigeeRegistry/src/V1/GetInstanceRequest.php index e86305e7c13b..5a543f33a744 100644 --- a/ApigeeRegistry/src/V1/GetInstanceRequest.php +++ b/ApigeeRegistry/src/V1/GetInstanceRequest.php @@ -23,6 +23,21 @@ class GetInstanceRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The name of the Instance to retrieve. + * Format: `projects/*/locations/*/instances/*`. Please see + * {@see ProvisioningClient::instanceName()} for help formatting this field. + * + * @return \Google\Cloud\ApigeeRegistry\V1\GetInstanceRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/ApigeeRegistry/src/V1/ListApiDeploymentsRequest.php b/ApigeeRegistry/src/V1/ListApiDeploymentsRequest.php index 2cf875a3e099..d39b022ba014 100644 --- a/ApigeeRegistry/src/V1/ListApiDeploymentsRequest.php +++ b/ApigeeRegistry/src/V1/ListApiDeploymentsRequest.php @@ -48,6 +48,21 @@ class ListApiDeploymentsRequest extends \Google\Protobuf\Internal\Message */ private $filter = ''; + /** + * @param string $parent Required. The parent, which owns this collection of deployments. + * Format: `projects/*/locations/*/apis/*` + * Please see {@see RegistryClient::apiName()} for help formatting this field. + * + * @return \Google\Cloud\ApigeeRegistry\V1\ListApiDeploymentsRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/ApigeeRegistry/src/V1/ListApiSpecsRequest.php b/ApigeeRegistry/src/V1/ListApiSpecsRequest.php index f491680b3301..62f1cb0fa1c9 100644 --- a/ApigeeRegistry/src/V1/ListApiSpecsRequest.php +++ b/ApigeeRegistry/src/V1/ListApiSpecsRequest.php @@ -48,6 +48,21 @@ class ListApiSpecsRequest extends \Google\Protobuf\Internal\Message */ private $filter = ''; + /** + * @param string $parent Required. The parent, which owns this collection of specs. + * Format: `projects/*/locations/*/apis/*/versions/*` + * Please see {@see RegistryClient::apiVersionName()} for help formatting this field. + * + * @return \Google\Cloud\ApigeeRegistry\V1\ListApiSpecsRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/ApigeeRegistry/src/V1/ListApiVersionsRequest.php b/ApigeeRegistry/src/V1/ListApiVersionsRequest.php index 89d073da0ae7..34864ef7f5b7 100644 --- a/ApigeeRegistry/src/V1/ListApiVersionsRequest.php +++ b/ApigeeRegistry/src/V1/ListApiVersionsRequest.php @@ -48,6 +48,21 @@ class ListApiVersionsRequest extends \Google\Protobuf\Internal\Message */ private $filter = ''; + /** + * @param string $parent Required. The parent, which owns this collection of versions. + * Format: `projects/*/locations/*/apis/*` + * Please see {@see RegistryClient::apiName()} for help formatting this field. + * + * @return \Google\Cloud\ApigeeRegistry\V1\ListApiVersionsRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/ApigeeRegistry/src/V1/ListApisRequest.php b/ApigeeRegistry/src/V1/ListApisRequest.php index 0114dfb2b39b..156e0018bcc4 100644 --- a/ApigeeRegistry/src/V1/ListApisRequest.php +++ b/ApigeeRegistry/src/V1/ListApisRequest.php @@ -48,6 +48,21 @@ class ListApisRequest extends \Google\Protobuf\Internal\Message */ private $filter = ''; + /** + * @param string $parent Required. The parent, which owns this collection of APIs. + * Format: `projects/*/locations/*` + * Please see {@see RegistryClient::locationName()} for help formatting this field. + * + * @return \Google\Cloud\ApigeeRegistry\V1\ListApisRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/ApigeeRegistry/src/V1/ListArtifactsRequest.php b/ApigeeRegistry/src/V1/ListArtifactsRequest.php index a2ec41114dd4..d659134df272 100644 --- a/ApigeeRegistry/src/V1/ListArtifactsRequest.php +++ b/ApigeeRegistry/src/V1/ListArtifactsRequest.php @@ -48,6 +48,21 @@ class ListArtifactsRequest extends \Google\Protobuf\Internal\Message */ private $filter = ''; + /** + * @param string $parent Required. The parent, which owns this collection of artifacts. + * Format: `{parent}` + * Please see {@see RegistryClient::locationName()} for help formatting this field. + * + * @return \Google\Cloud\ApigeeRegistry\V1\ListArtifactsRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/ApigeeRegistry/src/V1/ReplaceArtifactRequest.php b/ApigeeRegistry/src/V1/ReplaceArtifactRequest.php index 252e155b2a66..a24aec494003 100644 --- a/ApigeeRegistry/src/V1/ReplaceArtifactRequest.php +++ b/ApigeeRegistry/src/V1/ReplaceArtifactRequest.php @@ -24,6 +24,22 @@ class ReplaceArtifactRequest extends \Google\Protobuf\Internal\Message */ private $artifact = null; + /** + * @param \Google\Cloud\ApigeeRegistry\V1\Artifact $artifact Required. The artifact to replace. + * + * The `name` field is used to identify the artifact to replace. + * Format: `{parent}/artifacts/*` + * + * @return \Google\Cloud\ApigeeRegistry\V1\ReplaceArtifactRequest + * + * @experimental + */ + public static function build(\Google\Cloud\ApigeeRegistry\V1\Artifact $artifact): self + { + return (new self()) + ->setArtifact($artifact); + } + /** * Constructor. * diff --git a/ApigeeRegistry/src/V1/UpdateApiDeploymentRequest.php b/ApigeeRegistry/src/V1/UpdateApiDeploymentRequest.php index 1c90348fd500..01d3fb9f10ce 100644 --- a/ApigeeRegistry/src/V1/UpdateApiDeploymentRequest.php +++ b/ApigeeRegistry/src/V1/UpdateApiDeploymentRequest.php @@ -40,6 +40,27 @@ class UpdateApiDeploymentRequest extends \Google\Protobuf\Internal\Message */ private $allow_missing = false; + /** + * @param \Google\Cloud\ApigeeRegistry\V1\ApiDeployment $apiDeployment Required. The deployment to update. + * + * The `name` field is used to identify the deployment to update. + * Format: `projects/*/locations/*/apis/*/deployments/*` + * @param \Google\Protobuf\FieldMask $updateMask The list of fields to be updated. If omitted, all fields are updated that + * are set in the request message (fields set to default values are ignored). + * If an asterisk "*" is specified, all fields are updated, including fields + * that are unspecified/default in the request. + * + * @return \Google\Cloud\ApigeeRegistry\V1\UpdateApiDeploymentRequest + * + * @experimental + */ + public static function build(\Google\Cloud\ApigeeRegistry\V1\ApiDeployment $apiDeployment, \Google\Protobuf\FieldMask $updateMask): self + { + return (new self()) + ->setApiDeployment($apiDeployment) + ->setUpdateMask($updateMask); + } + /** * Constructor. * diff --git a/ApigeeRegistry/src/V1/UpdateApiRequest.php b/ApigeeRegistry/src/V1/UpdateApiRequest.php index ecadbe94ccd6..bb75c4850b1b 100644 --- a/ApigeeRegistry/src/V1/UpdateApiRequest.php +++ b/ApigeeRegistry/src/V1/UpdateApiRequest.php @@ -40,6 +40,27 @@ class UpdateApiRequest extends \Google\Protobuf\Internal\Message */ private $allow_missing = false; + /** + * @param \Google\Cloud\ApigeeRegistry\V1\Api $api Required. The API to update. + * + * The `name` field is used to identify the API to update. + * Format: `projects/*/locations/*/apis/*` + * @param \Google\Protobuf\FieldMask $updateMask The list of fields to be updated. If omitted, all fields are updated that + * are set in the request message (fields set to default values are ignored). + * If an asterisk "*" is specified, all fields are updated, including fields + * that are unspecified/default in the request. + * + * @return \Google\Cloud\ApigeeRegistry\V1\UpdateApiRequest + * + * @experimental + */ + public static function build(\Google\Cloud\ApigeeRegistry\V1\Api $api, \Google\Protobuf\FieldMask $updateMask): self + { + return (new self()) + ->setApi($api) + ->setUpdateMask($updateMask); + } + /** * Constructor. * diff --git a/ApigeeRegistry/src/V1/UpdateApiSpecRequest.php b/ApigeeRegistry/src/V1/UpdateApiSpecRequest.php index 2f6a8061bd76..ec048cb4518f 100644 --- a/ApigeeRegistry/src/V1/UpdateApiSpecRequest.php +++ b/ApigeeRegistry/src/V1/UpdateApiSpecRequest.php @@ -40,6 +40,27 @@ class UpdateApiSpecRequest extends \Google\Protobuf\Internal\Message */ private $allow_missing = false; + /** + * @param \Google\Cloud\ApigeeRegistry\V1\ApiSpec $apiSpec Required. The spec to update. + * + * The `name` field is used to identify the spec to update. + * Format: `projects/*/locations/*/apis/*/versions/*/specs/*` + * @param \Google\Protobuf\FieldMask $updateMask The list of fields to be updated. If omitted, all fields are updated that + * are set in the request message (fields set to default values are ignored). + * If an asterisk "*" is specified, all fields are updated, including fields + * that are unspecified/default in the request. + * + * @return \Google\Cloud\ApigeeRegistry\V1\UpdateApiSpecRequest + * + * @experimental + */ + public static function build(\Google\Cloud\ApigeeRegistry\V1\ApiSpec $apiSpec, \Google\Protobuf\FieldMask $updateMask): self + { + return (new self()) + ->setApiSpec($apiSpec) + ->setUpdateMask($updateMask); + } + /** * Constructor. * diff --git a/ApigeeRegistry/src/V1/UpdateApiVersionRequest.php b/ApigeeRegistry/src/V1/UpdateApiVersionRequest.php index 28bf752bafce..5216896779c0 100644 --- a/ApigeeRegistry/src/V1/UpdateApiVersionRequest.php +++ b/ApigeeRegistry/src/V1/UpdateApiVersionRequest.php @@ -40,6 +40,27 @@ class UpdateApiVersionRequest extends \Google\Protobuf\Internal\Message */ private $allow_missing = false; + /** + * @param \Google\Cloud\ApigeeRegistry\V1\ApiVersion $apiVersion Required. The version to update. + * + * The `name` field is used to identify the version to update. + * Format: `projects/*/locations/*/apis/*/versions/*` + * @param \Google\Protobuf\FieldMask $updateMask The list of fields to be updated. If omitted, all fields are updated that + * are set in the request message (fields set to default values are ignored). + * If an asterisk "*" is specified, all fields are updated, including fields + * that are unspecified/default in the request. + * + * @return \Google\Cloud\ApigeeRegistry\V1\UpdateApiVersionRequest + * + * @experimental + */ + public static function build(\Google\Cloud\ApigeeRegistry\V1\ApiVersion $apiVersion, \Google\Protobuf\FieldMask $updateMask): self + { + return (new self()) + ->setApiVersion($apiVersion) + ->setUpdateMask($updateMask); + } + /** * Constructor. * diff --git a/ApigeeRegistry/src/V1/resources/provisioning_descriptor_config.php b/ApigeeRegistry/src/V1/resources/provisioning_descriptor_config.php index 3d5ad2f83001..2bffad392f97 100644 --- a/ApigeeRegistry/src/V1/resources/provisioning_descriptor_config.php +++ b/ApigeeRegistry/src/V1/resources/provisioning_descriptor_config.php @@ -12,6 +12,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'DeleteInstance' => [ 'longRunning' => [ @@ -22,8 +31,39 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetInstance' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\ApigeeRegistry\V1\Instance', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'GetLocation' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Location\Location', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], 'interfaceOverride' => 'google.cloud.location.Locations', ], 'ListLocations' => [ @@ -35,17 +75,61 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getLocations', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\Location\ListLocationsResponse', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], 'interfaceOverride' => 'google.cloud.location.Locations', ], 'GetIamPolicy' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\Policy', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], 'interfaceOverride' => 'google.iam.v1.IAMPolicy', ], 'SetIamPolicy' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\Policy', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], 'interfaceOverride' => 'google.iam.v1.IAMPolicy', ], 'TestIamPermissions' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\TestIamPermissionsResponse', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], 'interfaceOverride' => 'google.iam.v1.IAMPolicy', ], + 'templateMap' => [ + 'instance' => 'projects/{project}/locations/{location}/instances/{instance}', + 'location' => 'projects/{project}/locations/{location}', + ], ], ], ]; diff --git a/ApigeeRegistry/src/V1/resources/registry_descriptor_config.php b/ApigeeRegistry/src/V1/resources/registry_descriptor_config.php index 528952f6ae68..7d53a500a7e2 100644 --- a/ApigeeRegistry/src/V1/resources/registry_descriptor_config.php +++ b/ApigeeRegistry/src/V1/resources/registry_descriptor_config.php @@ -3,6 +3,234 @@ return [ 'interfaces' => [ 'google.cloud.apigeeregistry.v1.Registry' => [ + 'CreateApi' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\ApigeeRegistry\V1\Api', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'CreateApiDeployment' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\ApigeeRegistry\V1\ApiDeployment', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'CreateApiSpec' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\ApigeeRegistry\V1\ApiSpec', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'CreateApiVersion' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\ApigeeRegistry\V1\ApiVersion', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'CreateArtifact' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\ApigeeRegistry\V1\Artifact', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'DeleteApi' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Protobuf\GPBEmpty', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'DeleteApiDeployment' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Protobuf\GPBEmpty', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'DeleteApiDeploymentRevision' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\ApigeeRegistry\V1\ApiDeployment', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'DeleteApiSpec' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Protobuf\GPBEmpty', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'DeleteApiSpecRevision' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\ApigeeRegistry\V1\ApiSpec', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'DeleteApiVersion' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Protobuf\GPBEmpty', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'DeleteArtifact' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Protobuf\GPBEmpty', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetApi' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\ApigeeRegistry\V1\Api', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetApiDeployment' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\ApigeeRegistry\V1\ApiDeployment', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetApiSpec' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\ApigeeRegistry\V1\ApiSpec', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetApiSpecContents' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Api\HttpBody', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetApiVersion' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\ApigeeRegistry\V1\ApiVersion', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetArtifact' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\ApigeeRegistry\V1\Artifact', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetArtifactContents' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Api\HttpBody', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], 'ListApiDeploymentRevisions' => [ 'pageStreaming' => [ 'requestPageTokenGetMethod' => 'getPageToken', @@ -12,6 +240,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getApiDeployments', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\ApigeeRegistry\V1\ListApiDeploymentRevisionsResponse', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'ListApiDeployments' => [ 'pageStreaming' => [ @@ -22,6 +260,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getApiDeployments', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\ApigeeRegistry\V1\ListApiDeploymentsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ListApiSpecRevisions' => [ 'pageStreaming' => [ @@ -32,6 +280,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getApiSpecs', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\ApigeeRegistry\V1\ListApiSpecRevisionsResponse', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'ListApiSpecs' => [ 'pageStreaming' => [ @@ -42,6 +300,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getApiSpecs', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\ApigeeRegistry\V1\ListApiSpecsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ListApiVersions' => [ 'pageStreaming' => [ @@ -52,6 +320,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getApiVersions', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\ApigeeRegistry\V1\ListApiVersionsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ListApis' => [ 'pageStreaming' => [ @@ -62,6 +340,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getApis', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\ApigeeRegistry\V1\ListApisResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ListArtifacts' => [ 'pageStreaming' => [ @@ -72,8 +360,141 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getArtifacts', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\ApigeeRegistry\V1\ListArtifactsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'ReplaceArtifact' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\ApigeeRegistry\V1\Artifact', + 'headerParams' => [ + [ + 'keyName' => 'artifact.name', + 'fieldAccessors' => [ + 'getArtifact', + 'getName', + ], + ], + ], + ], + 'RollbackApiDeployment' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\ApigeeRegistry\V1\ApiDeployment', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'RollbackApiSpec' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\ApigeeRegistry\V1\ApiSpec', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'TagApiDeploymentRevision' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\ApigeeRegistry\V1\ApiDeployment', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'TagApiSpecRevision' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\ApigeeRegistry\V1\ApiSpec', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'UpdateApi' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\ApigeeRegistry\V1\Api', + 'headerParams' => [ + [ + 'keyName' => 'api.name', + 'fieldAccessors' => [ + 'getApi', + 'getName', + ], + ], + ], + ], + 'UpdateApiDeployment' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\ApigeeRegistry\V1\ApiDeployment', + 'headerParams' => [ + [ + 'keyName' => 'api_deployment.name', + 'fieldAccessors' => [ + 'getApiDeployment', + 'getName', + ], + ], + ], + ], + 'UpdateApiSpec' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\ApigeeRegistry\V1\ApiSpec', + 'headerParams' => [ + [ + 'keyName' => 'api_spec.name', + 'fieldAccessors' => [ + 'getApiSpec', + 'getName', + ], + ], + ], + ], + 'UpdateApiVersion' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\ApigeeRegistry\V1\ApiVersion', + 'headerParams' => [ + [ + 'keyName' => 'api_version.name', + 'fieldAccessors' => [ + 'getApiVersion', + 'getName', + ], + ], + ], ], 'GetLocation' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Location\Location', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], 'interfaceOverride' => 'google.cloud.location.Locations', ], 'ListLocations' => [ @@ -85,17 +506,70 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getLocations', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\Location\ListLocationsResponse', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], 'interfaceOverride' => 'google.cloud.location.Locations', ], 'GetIamPolicy' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\Policy', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], 'interfaceOverride' => 'google.iam.v1.IAMPolicy', ], 'SetIamPolicy' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\Policy', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], 'interfaceOverride' => 'google.iam.v1.IAMPolicy', ], 'TestIamPermissions' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\TestIamPermissionsResponse', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], 'interfaceOverride' => 'google.iam.v1.IAMPolicy', ], + 'templateMap' => [ + 'api' => 'projects/{project}/locations/{location}/apis/{api}', + 'apiDeployment' => 'projects/{project}/locations/{location}/apis/{api}/deployments/{deployment}', + 'apiSpec' => 'projects/{project}/locations/{location}/apis/{api}/versions/{version}/specs/{spec}', + 'apiVersion' => 'projects/{project}/locations/{location}/apis/{api}/versions/{version}', + 'artifact' => 'projects/{project}/locations/{location}/artifacts/{artifact}', + 'location' => 'projects/{project}/locations/{location}', + 'projectLocationApiArtifact' => 'projects/{project}/locations/{location}/apis/{api}/artifacts/{artifact}', + 'projectLocationApiDeploymentArtifact' => 'projects/{project}/locations/{location}/apis/{api}/deployments/{deployment}/artifacts/{artifact}', + 'projectLocationApiVersionArtifact' => 'projects/{project}/locations/{location}/apis/{api}/versions/{version}/artifacts/{artifact}', + 'projectLocationApiVersionSpecArtifact' => 'projects/{project}/locations/{location}/apis/{api}/versions/{version}/specs/{spec}/artifacts/{artifact}', + 'projectLocationArtifact' => 'projects/{project}/locations/{location}/artifacts/{artifact}', + ], ], ], ]; diff --git a/ApigeeRegistry/tests/Unit/V1/Client/ProvisioningClientTest.php b/ApigeeRegistry/tests/Unit/V1/Client/ProvisioningClientTest.php new file mode 100644 index 000000000000..a8724dbf3925 --- /dev/null +++ b/ApigeeRegistry/tests/Unit/V1/Client/ProvisioningClientTest.php @@ -0,0 +1,821 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return ProvisioningClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new ProvisioningClient($options); + } + + /** @test */ + public function createInstanceTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/createInstanceTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $stateMessage = 'stateMessage29641305'; + $expectedResponse = new Instance(); + $expectedResponse->setName($name); + $expectedResponse->setStateMessage($stateMessage); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createInstanceTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $instanceId = 'instanceId-2101995259'; + $instance = new Instance(); + $instanceConfig = new Config(); + $configCmekKeyName = 'configCmekKeyName-1633313736'; + $instanceConfig->setCmekKeyName($configCmekKeyName); + $instance->setConfig($instanceConfig); + $request = (new CreateInstanceRequest()) + ->setParent($formattedParent) + ->setInstanceId($instanceId) + ->setInstance($instance); + $response = $gapicClient->createInstance($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.apigeeregistry.v1.Provisioning/CreateInstance', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getInstanceId(); + $this->assertProtobufEquals($instanceId, $actualValue); + $actualValue = $actualApiRequestObject->getInstance(); + $this->assertProtobufEquals($instance, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createInstanceTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function createInstanceExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/createInstanceTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $instanceId = 'instanceId-2101995259'; + $instance = new Instance(); + $instanceConfig = new Config(); + $configCmekKeyName = 'configCmekKeyName-1633313736'; + $instanceConfig->setCmekKeyName($configCmekKeyName); + $instance->setConfig($instanceConfig); + $request = (new CreateInstanceRequest()) + ->setParent($formattedParent) + ->setInstanceId($instanceId) + ->setInstance($instance); + $response = $gapicClient->createInstance($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createInstanceTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function deleteInstanceTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/deleteInstanceTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new GPBEmpty(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/deleteInstanceTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->instanceName('[PROJECT]', '[LOCATION]', '[INSTANCE]'); + $request = (new DeleteInstanceRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteInstance($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.apigeeregistry.v1.Provisioning/DeleteInstance', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteInstanceTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function deleteInstanceExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/deleteInstanceTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->instanceName('[PROJECT]', '[LOCATION]', '[INSTANCE]'); + $request = (new DeleteInstanceRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteInstance($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteInstanceTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function getInstanceTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $stateMessage = 'stateMessage29641305'; + $expectedResponse = new Instance(); + $expectedResponse->setName($name2); + $expectedResponse->setStateMessage($stateMessage); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->instanceName('[PROJECT]', '[LOCATION]', '[INSTANCE]'); + $request = (new GetInstanceRequest()) + ->setName($formattedName); + $response = $gapicClient->getInstance($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.apigeeregistry.v1.Provisioning/GetInstance', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getInstanceExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->instanceName('[PROJECT]', '[LOCATION]', '[INSTANCE]'); + $request = (new GetInstanceRequest()) + ->setName($formattedName); + try { + $gapicClient->getInstance($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getLocationTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $locationId = 'locationId552319461'; + $displayName = 'displayName1615086568'; + $expectedResponse = new Location(); + $expectedResponse->setName($name2); + $expectedResponse->setLocationId($locationId); + $expectedResponse->setDisplayName($displayName); + $transport->addResponse($expectedResponse); + $request = new GetLocationRequest(); + $response = $gapicClient->getLocation($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.location.Locations/GetLocation', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getLocationExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + $request = new GetLocationRequest(); + try { + $gapicClient->getLocation($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listLocationsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $locationsElement = new Location(); + $locations = [ + $locationsElement, + ]; + $expectedResponse = new ListLocationsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setLocations($locations); + $transport->addResponse($expectedResponse); + $request = new ListLocationsRequest(); + $response = $gapicClient->listLocations($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getLocations()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.location.Locations/ListLocations', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listLocationsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + $request = new ListLocationsRequest(); + try { + $gapicClient->listLocations($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getIamPolicyTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $version = 351608024; + $etag = '21'; + $expectedResponse = new Policy(); + $expectedResponse->setVersion($version); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + $response = $gapicClient->getIamPolicy($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.iam.v1.IAMPolicy/GetIamPolicy', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getIamPolicyExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $resource = 'resource-341064690'; + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + try { + $gapicClient->getIamPolicy($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function setIamPolicyTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $version = 351608024; + $etag = '21'; + $expectedResponse = new Policy(); + $expectedResponse->setVersion($version); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $policy = new Policy(); + $request = (new SetIamPolicyRequest()) + ->setResource($resource) + ->setPolicy($policy); + $response = $gapicClient->setIamPolicy($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.iam.v1.IAMPolicy/SetIamPolicy', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $actualValue = $actualRequestObject->getPolicy(); + $this->assertProtobufEquals($policy, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function setIamPolicyExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $resource = 'resource-341064690'; + $policy = new Policy(); + $request = (new SetIamPolicyRequest()) + ->setResource($resource) + ->setPolicy($policy); + try { + $gapicClient->setIamPolicy($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function testIamPermissionsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new TestIamPermissionsResponse(); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $permissions = []; + $request = (new TestIamPermissionsRequest()) + ->setResource($resource) + ->setPermissions($permissions); + $response = $gapicClient->testIamPermissions($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.iam.v1.IAMPolicy/TestIamPermissions', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $actualValue = $actualRequestObject->getPermissions(); + $this->assertProtobufEquals($permissions, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function testIamPermissionsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $resource = 'resource-341064690'; + $permissions = []; + $request = (new TestIamPermissionsRequest()) + ->setResource($resource) + ->setPermissions($permissions); + try { + $gapicClient->testIamPermissions($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createInstanceAsyncTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/createInstanceTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $stateMessage = 'stateMessage29641305'; + $expectedResponse = new Instance(); + $expectedResponse->setName($name); + $expectedResponse->setStateMessage($stateMessage); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createInstanceTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $instanceId = 'instanceId-2101995259'; + $instance = new Instance(); + $instanceConfig = new Config(); + $configCmekKeyName = 'configCmekKeyName-1633313736'; + $instanceConfig->setCmekKeyName($configCmekKeyName); + $instance->setConfig($instanceConfig); + $request = (new CreateInstanceRequest()) + ->setParent($formattedParent) + ->setInstanceId($instanceId) + ->setInstance($instance); + $response = $gapicClient->createInstanceAsync($request)->wait(); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.apigeeregistry.v1.Provisioning/CreateInstance', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getInstanceId(); + $this->assertProtobufEquals($instanceId, $actualValue); + $actualValue = $actualApiRequestObject->getInstance(); + $this->assertProtobufEquals($instance, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createInstanceTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } +} diff --git a/ApigeeRegistry/tests/Unit/V1/Client/RegistryClientTest.php b/ApigeeRegistry/tests/Unit/V1/Client/RegistryClientTest.php new file mode 100644 index 000000000000..e09a9d4220a9 --- /dev/null +++ b/ApigeeRegistry/tests/Unit/V1/Client/RegistryClientTest.php @@ -0,0 +1,3128 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return RegistryClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new RegistryClient($options); + } + + /** @test */ + public function createApiTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $displayName = 'displayName1615086568'; + $description = 'description-1724546052'; + $availability = 'availability1997542747'; + $recommendedVersion = 'recommendedVersion265230068'; + $recommendedDeployment = 'recommendedDeployment1339243305'; + $expectedResponse = new Api(); + $expectedResponse->setName($name); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setDescription($description); + $expectedResponse->setAvailability($availability); + $expectedResponse->setRecommendedVersion($recommendedVersion); + $expectedResponse->setRecommendedDeployment($recommendedDeployment); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $api = new Api(); + $apiId = 'apiId-1411282592'; + $request = (new CreateApiRequest()) + ->setParent($formattedParent) + ->setApi($api) + ->setApiId($apiId); + $response = $gapicClient->createApi($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.apigeeregistry.v1.Registry/CreateApi', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getApi(); + $this->assertProtobufEquals($api, $actualValue); + $actualValue = $actualRequestObject->getApiId(); + $this->assertProtobufEquals($apiId, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createApiExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $api = new Api(); + $apiId = 'apiId-1411282592'; + $request = (new CreateApiRequest()) + ->setParent($formattedParent) + ->setApi($api) + ->setApiId($apiId); + try { + $gapicClient->createApi($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createApiDeploymentTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $displayName = 'displayName1615086568'; + $description = 'description-1724546052'; + $revisionId = 'revisionId513861631'; + $apiSpecRevision = 'apiSpecRevision-1685452166'; + $endpointUri = 'endpointUri-850313278'; + $externalChannelUri = 'externalChannelUri-559177284'; + $intendedAudience = 'intendedAudience-1100067944'; + $accessGuidance = 'accessGuidance24590291'; + $expectedResponse = new ApiDeployment(); + $expectedResponse->setName($name); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setDescription($description); + $expectedResponse->setRevisionId($revisionId); + $expectedResponse->setApiSpecRevision($apiSpecRevision); + $expectedResponse->setEndpointUri($endpointUri); + $expectedResponse->setExternalChannelUri($externalChannelUri); + $expectedResponse->setIntendedAudience($intendedAudience); + $expectedResponse->setAccessGuidance($accessGuidance); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->apiName('[PROJECT]', '[LOCATION]', '[API]'); + $apiDeployment = new ApiDeployment(); + $apiDeploymentId = 'apiDeploymentId-276259984'; + $request = (new CreateApiDeploymentRequest()) + ->setParent($formattedParent) + ->setApiDeployment($apiDeployment) + ->setApiDeploymentId($apiDeploymentId); + $response = $gapicClient->createApiDeployment($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.apigeeregistry.v1.Registry/CreateApiDeployment', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getApiDeployment(); + $this->assertProtobufEquals($apiDeployment, $actualValue); + $actualValue = $actualRequestObject->getApiDeploymentId(); + $this->assertProtobufEquals($apiDeploymentId, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createApiDeploymentExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->apiName('[PROJECT]', '[LOCATION]', '[API]'); + $apiDeployment = new ApiDeployment(); + $apiDeploymentId = 'apiDeploymentId-276259984'; + $request = (new CreateApiDeploymentRequest()) + ->setParent($formattedParent) + ->setApiDeployment($apiDeployment) + ->setApiDeploymentId($apiDeploymentId); + try { + $gapicClient->createApiDeployment($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createApiSpecTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $filename = 'filename-734768633'; + $description = 'description-1724546052'; + $revisionId = 'revisionId513861631'; + $mimeType = 'mimeType-196041627'; + $sizeBytes = 1796325715; + $hash = 'hash3195150'; + $sourceUri = 'sourceUri-1111107768'; + $contents = '26'; + $expectedResponse = new ApiSpec(); + $expectedResponse->setName($name); + $expectedResponse->setFilename($filename); + $expectedResponse->setDescription($description); + $expectedResponse->setRevisionId($revisionId); + $expectedResponse->setMimeType($mimeType); + $expectedResponse->setSizeBytes($sizeBytes); + $expectedResponse->setHash($hash); + $expectedResponse->setSourceUri($sourceUri); + $expectedResponse->setContents($contents); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->apiVersionName('[PROJECT]', '[LOCATION]', '[API]', '[VERSION]'); + $apiSpec = new ApiSpec(); + $apiSpecId = 'apiSpecId800293626'; + $request = (new CreateApiSpecRequest()) + ->setParent($formattedParent) + ->setApiSpec($apiSpec) + ->setApiSpecId($apiSpecId); + $response = $gapicClient->createApiSpec($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.apigeeregistry.v1.Registry/CreateApiSpec', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getApiSpec(); + $this->assertProtobufEquals($apiSpec, $actualValue); + $actualValue = $actualRequestObject->getApiSpecId(); + $this->assertProtobufEquals($apiSpecId, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createApiSpecExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->apiVersionName('[PROJECT]', '[LOCATION]', '[API]', '[VERSION]'); + $apiSpec = new ApiSpec(); + $apiSpecId = 'apiSpecId800293626'; + $request = (new CreateApiSpecRequest()) + ->setParent($formattedParent) + ->setApiSpec($apiSpec) + ->setApiSpecId($apiSpecId); + try { + $gapicClient->createApiSpec($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createApiVersionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $displayName = 'displayName1615086568'; + $description = 'description-1724546052'; + $state = 'state109757585'; + $expectedResponse = new ApiVersion(); + $expectedResponse->setName($name); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setDescription($description); + $expectedResponse->setState($state); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->apiName('[PROJECT]', '[LOCATION]', '[API]'); + $apiVersion = new ApiVersion(); + $apiVersionId = 'apiVersionId790654247'; + $request = (new CreateApiVersionRequest()) + ->setParent($formattedParent) + ->setApiVersion($apiVersion) + ->setApiVersionId($apiVersionId); + $response = $gapicClient->createApiVersion($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.apigeeregistry.v1.Registry/CreateApiVersion', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getApiVersion(); + $this->assertProtobufEquals($apiVersion, $actualValue); + $actualValue = $actualRequestObject->getApiVersionId(); + $this->assertProtobufEquals($apiVersionId, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createApiVersionExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->apiName('[PROJECT]', '[LOCATION]', '[API]'); + $apiVersion = new ApiVersion(); + $apiVersionId = 'apiVersionId790654247'; + $request = (new CreateApiVersionRequest()) + ->setParent($formattedParent) + ->setApiVersion($apiVersion) + ->setApiVersionId($apiVersionId); + try { + $gapicClient->createApiVersion($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createArtifactTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $mimeType = 'mimeType-196041627'; + $sizeBytes = 1796325715; + $hash = 'hash3195150'; + $contents = '26'; + $expectedResponse = new Artifact(); + $expectedResponse->setName($name); + $expectedResponse->setMimeType($mimeType); + $expectedResponse->setSizeBytes($sizeBytes); + $expectedResponse->setHash($hash); + $expectedResponse->setContents($contents); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $artifact = new Artifact(); + $artifactId = 'artifactId-1130052952'; + $request = (new CreateArtifactRequest()) + ->setParent($formattedParent) + ->setArtifact($artifact) + ->setArtifactId($artifactId); + $response = $gapicClient->createArtifact($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.apigeeregistry.v1.Registry/CreateArtifact', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getArtifact(); + $this->assertProtobufEquals($artifact, $actualValue); + $actualValue = $actualRequestObject->getArtifactId(); + $this->assertProtobufEquals($artifactId, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createArtifactExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $artifact = new Artifact(); + $artifactId = 'artifactId-1130052952'; + $request = (new CreateArtifactRequest()) + ->setParent($formattedParent) + ->setArtifact($artifact) + ->setArtifactId($artifactId); + try { + $gapicClient->createArtifact($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteApiTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new GPBEmpty(); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->apiName('[PROJECT]', '[LOCATION]', '[API]'); + $request = (new DeleteApiRequest()) + ->setName($formattedName); + $gapicClient->deleteApi($request); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.apigeeregistry.v1.Registry/DeleteApi', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteApiExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->apiName('[PROJECT]', '[LOCATION]', '[API]'); + $request = (new DeleteApiRequest()) + ->setName($formattedName); + try { + $gapicClient->deleteApi($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteApiDeploymentTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new GPBEmpty(); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->apiDeploymentName('[PROJECT]', '[LOCATION]', '[API]', '[DEPLOYMENT]'); + $request = (new DeleteApiDeploymentRequest()) + ->setName($formattedName); + $gapicClient->deleteApiDeployment($request); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.apigeeregistry.v1.Registry/DeleteApiDeployment', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteApiDeploymentExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->apiDeploymentName('[PROJECT]', '[LOCATION]', '[API]', '[DEPLOYMENT]'); + $request = (new DeleteApiDeploymentRequest()) + ->setName($formattedName); + try { + $gapicClient->deleteApiDeployment($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteApiDeploymentRevisionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $displayName = 'displayName1615086568'; + $description = 'description-1724546052'; + $revisionId = 'revisionId513861631'; + $apiSpecRevision = 'apiSpecRevision-1685452166'; + $endpointUri = 'endpointUri-850313278'; + $externalChannelUri = 'externalChannelUri-559177284'; + $intendedAudience = 'intendedAudience-1100067944'; + $accessGuidance = 'accessGuidance24590291'; + $expectedResponse = new ApiDeployment(); + $expectedResponse->setName($name2); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setDescription($description); + $expectedResponse->setRevisionId($revisionId); + $expectedResponse->setApiSpecRevision($apiSpecRevision); + $expectedResponse->setEndpointUri($endpointUri); + $expectedResponse->setExternalChannelUri($externalChannelUri); + $expectedResponse->setIntendedAudience($intendedAudience); + $expectedResponse->setAccessGuidance($accessGuidance); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->apiDeploymentName('[PROJECT]', '[LOCATION]', '[API]', '[DEPLOYMENT]'); + $request = (new DeleteApiDeploymentRevisionRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteApiDeploymentRevision($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.apigeeregistry.v1.Registry/DeleteApiDeploymentRevision', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteApiDeploymentRevisionExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->apiDeploymentName('[PROJECT]', '[LOCATION]', '[API]', '[DEPLOYMENT]'); + $request = (new DeleteApiDeploymentRevisionRequest()) + ->setName($formattedName); + try { + $gapicClient->deleteApiDeploymentRevision($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteApiSpecTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new GPBEmpty(); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->apiSpecName('[PROJECT]', '[LOCATION]', '[API]', '[VERSION]', '[SPEC]'); + $request = (new DeleteApiSpecRequest()) + ->setName($formattedName); + $gapicClient->deleteApiSpec($request); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.apigeeregistry.v1.Registry/DeleteApiSpec', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteApiSpecExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->apiSpecName('[PROJECT]', '[LOCATION]', '[API]', '[VERSION]', '[SPEC]'); + $request = (new DeleteApiSpecRequest()) + ->setName($formattedName); + try { + $gapicClient->deleteApiSpec($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteApiSpecRevisionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $filename = 'filename-734768633'; + $description = 'description-1724546052'; + $revisionId = 'revisionId513861631'; + $mimeType = 'mimeType-196041627'; + $sizeBytes = 1796325715; + $hash = 'hash3195150'; + $sourceUri = 'sourceUri-1111107768'; + $contents = '26'; + $expectedResponse = new ApiSpec(); + $expectedResponse->setName($name2); + $expectedResponse->setFilename($filename); + $expectedResponse->setDescription($description); + $expectedResponse->setRevisionId($revisionId); + $expectedResponse->setMimeType($mimeType); + $expectedResponse->setSizeBytes($sizeBytes); + $expectedResponse->setHash($hash); + $expectedResponse->setSourceUri($sourceUri); + $expectedResponse->setContents($contents); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->apiSpecName('[PROJECT]', '[LOCATION]', '[API]', '[VERSION]', '[SPEC]'); + $request = (new DeleteApiSpecRevisionRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteApiSpecRevision($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.apigeeregistry.v1.Registry/DeleteApiSpecRevision', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteApiSpecRevisionExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->apiSpecName('[PROJECT]', '[LOCATION]', '[API]', '[VERSION]', '[SPEC]'); + $request = (new DeleteApiSpecRevisionRequest()) + ->setName($formattedName); + try { + $gapicClient->deleteApiSpecRevision($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteApiVersionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new GPBEmpty(); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->apiVersionName('[PROJECT]', '[LOCATION]', '[API]', '[VERSION]'); + $request = (new DeleteApiVersionRequest()) + ->setName($formattedName); + $gapicClient->deleteApiVersion($request); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.apigeeregistry.v1.Registry/DeleteApiVersion', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteApiVersionExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->apiVersionName('[PROJECT]', '[LOCATION]', '[API]', '[VERSION]'); + $request = (new DeleteApiVersionRequest()) + ->setName($formattedName); + try { + $gapicClient->deleteApiVersion($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteArtifactTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new GPBEmpty(); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->artifactName('[PROJECT]', '[LOCATION]', '[ARTIFACT]'); + $request = (new DeleteArtifactRequest()) + ->setName($formattedName); + $gapicClient->deleteArtifact($request); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.apigeeregistry.v1.Registry/DeleteArtifact', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteArtifactExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->artifactName('[PROJECT]', '[LOCATION]', '[ARTIFACT]'); + $request = (new DeleteArtifactRequest()) + ->setName($formattedName); + try { + $gapicClient->deleteArtifact($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getApiTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $displayName = 'displayName1615086568'; + $description = 'description-1724546052'; + $availability = 'availability1997542747'; + $recommendedVersion = 'recommendedVersion265230068'; + $recommendedDeployment = 'recommendedDeployment1339243305'; + $expectedResponse = new Api(); + $expectedResponse->setName($name2); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setDescription($description); + $expectedResponse->setAvailability($availability); + $expectedResponse->setRecommendedVersion($recommendedVersion); + $expectedResponse->setRecommendedDeployment($recommendedDeployment); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->apiName('[PROJECT]', '[LOCATION]', '[API]'); + $request = (new GetApiRequest()) + ->setName($formattedName); + $response = $gapicClient->getApi($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.apigeeregistry.v1.Registry/GetApi', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getApiExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->apiName('[PROJECT]', '[LOCATION]', '[API]'); + $request = (new GetApiRequest()) + ->setName($formattedName); + try { + $gapicClient->getApi($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getApiDeploymentTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $displayName = 'displayName1615086568'; + $description = 'description-1724546052'; + $revisionId = 'revisionId513861631'; + $apiSpecRevision = 'apiSpecRevision-1685452166'; + $endpointUri = 'endpointUri-850313278'; + $externalChannelUri = 'externalChannelUri-559177284'; + $intendedAudience = 'intendedAudience-1100067944'; + $accessGuidance = 'accessGuidance24590291'; + $expectedResponse = new ApiDeployment(); + $expectedResponse->setName($name2); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setDescription($description); + $expectedResponse->setRevisionId($revisionId); + $expectedResponse->setApiSpecRevision($apiSpecRevision); + $expectedResponse->setEndpointUri($endpointUri); + $expectedResponse->setExternalChannelUri($externalChannelUri); + $expectedResponse->setIntendedAudience($intendedAudience); + $expectedResponse->setAccessGuidance($accessGuidance); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->apiDeploymentName('[PROJECT]', '[LOCATION]', '[API]', '[DEPLOYMENT]'); + $request = (new GetApiDeploymentRequest()) + ->setName($formattedName); + $response = $gapicClient->getApiDeployment($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.apigeeregistry.v1.Registry/GetApiDeployment', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getApiDeploymentExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->apiDeploymentName('[PROJECT]', '[LOCATION]', '[API]', '[DEPLOYMENT]'); + $request = (new GetApiDeploymentRequest()) + ->setName($formattedName); + try { + $gapicClient->getApiDeployment($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getApiSpecTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $filename = 'filename-734768633'; + $description = 'description-1724546052'; + $revisionId = 'revisionId513861631'; + $mimeType = 'mimeType-196041627'; + $sizeBytes = 1796325715; + $hash = 'hash3195150'; + $sourceUri = 'sourceUri-1111107768'; + $contents = '26'; + $expectedResponse = new ApiSpec(); + $expectedResponse->setName($name2); + $expectedResponse->setFilename($filename); + $expectedResponse->setDescription($description); + $expectedResponse->setRevisionId($revisionId); + $expectedResponse->setMimeType($mimeType); + $expectedResponse->setSizeBytes($sizeBytes); + $expectedResponse->setHash($hash); + $expectedResponse->setSourceUri($sourceUri); + $expectedResponse->setContents($contents); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->apiSpecName('[PROJECT]', '[LOCATION]', '[API]', '[VERSION]', '[SPEC]'); + $request = (new GetApiSpecRequest()) + ->setName($formattedName); + $response = $gapicClient->getApiSpec($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.apigeeregistry.v1.Registry/GetApiSpec', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getApiSpecExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->apiSpecName('[PROJECT]', '[LOCATION]', '[API]', '[VERSION]', '[SPEC]'); + $request = (new GetApiSpecRequest()) + ->setName($formattedName); + try { + $gapicClient->getApiSpec($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getApiSpecContentsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $contentType = 'contentType831846208'; + $data = '-86'; + $expectedResponse = new HttpBody(); + $expectedResponse->setContentType($contentType); + $expectedResponse->setData($data); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->apiSpecName('[PROJECT]', '[LOCATION]', '[API]', '[VERSION]', '[SPEC]'); + $request = (new GetApiSpecContentsRequest()) + ->setName($formattedName); + $response = $gapicClient->getApiSpecContents($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.apigeeregistry.v1.Registry/GetApiSpecContents', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getApiSpecContentsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->apiSpecName('[PROJECT]', '[LOCATION]', '[API]', '[VERSION]', '[SPEC]'); + $request = (new GetApiSpecContentsRequest()) + ->setName($formattedName); + try { + $gapicClient->getApiSpecContents($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getApiVersionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $displayName = 'displayName1615086568'; + $description = 'description-1724546052'; + $state = 'state109757585'; + $expectedResponse = new ApiVersion(); + $expectedResponse->setName($name2); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setDescription($description); + $expectedResponse->setState($state); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->apiVersionName('[PROJECT]', '[LOCATION]', '[API]', '[VERSION]'); + $request = (new GetApiVersionRequest()) + ->setName($formattedName); + $response = $gapicClient->getApiVersion($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.apigeeregistry.v1.Registry/GetApiVersion', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getApiVersionExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->apiVersionName('[PROJECT]', '[LOCATION]', '[API]', '[VERSION]'); + $request = (new GetApiVersionRequest()) + ->setName($formattedName); + try { + $gapicClient->getApiVersion($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getArtifactTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $mimeType = 'mimeType-196041627'; + $sizeBytes = 1796325715; + $hash = 'hash3195150'; + $contents = '26'; + $expectedResponse = new Artifact(); + $expectedResponse->setName($name2); + $expectedResponse->setMimeType($mimeType); + $expectedResponse->setSizeBytes($sizeBytes); + $expectedResponse->setHash($hash); + $expectedResponse->setContents($contents); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->artifactName('[PROJECT]', '[LOCATION]', '[ARTIFACT]'); + $request = (new GetArtifactRequest()) + ->setName($formattedName); + $response = $gapicClient->getArtifact($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.apigeeregistry.v1.Registry/GetArtifact', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getArtifactExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->artifactName('[PROJECT]', '[LOCATION]', '[ARTIFACT]'); + $request = (new GetArtifactRequest()) + ->setName($formattedName); + try { + $gapicClient->getArtifact($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getArtifactContentsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $contentType = 'contentType831846208'; + $data = '-86'; + $expectedResponse = new HttpBody(); + $expectedResponse->setContentType($contentType); + $expectedResponse->setData($data); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->artifactName('[PROJECT]', '[LOCATION]', '[ARTIFACT]'); + $request = (new GetArtifactContentsRequest()) + ->setName($formattedName); + $response = $gapicClient->getArtifactContents($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.apigeeregistry.v1.Registry/GetArtifactContents', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getArtifactContentsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->artifactName('[PROJECT]', '[LOCATION]', '[ARTIFACT]'); + $request = (new GetArtifactContentsRequest()) + ->setName($formattedName); + try { + $gapicClient->getArtifactContents($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listApiDeploymentRevisionsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $apiDeploymentsElement = new ApiDeployment(); + $apiDeployments = [ + $apiDeploymentsElement, + ]; + $expectedResponse = new ListApiDeploymentRevisionsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setApiDeployments($apiDeployments); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->apiDeploymentName('[PROJECT]', '[LOCATION]', '[API]', '[DEPLOYMENT]'); + $request = (new ListApiDeploymentRevisionsRequest()) + ->setName($formattedName); + $response = $gapicClient->listApiDeploymentRevisions($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getApiDeployments()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.apigeeregistry.v1.Registry/ListApiDeploymentRevisions', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listApiDeploymentRevisionsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->apiDeploymentName('[PROJECT]', '[LOCATION]', '[API]', '[DEPLOYMENT]'); + $request = (new ListApiDeploymentRevisionsRequest()) + ->setName($formattedName); + try { + $gapicClient->listApiDeploymentRevisions($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listApiDeploymentsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $apiDeploymentsElement = new ApiDeployment(); + $apiDeployments = [ + $apiDeploymentsElement, + ]; + $expectedResponse = new ListApiDeploymentsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setApiDeployments($apiDeployments); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->apiName('[PROJECT]', '[LOCATION]', '[API]'); + $request = (new ListApiDeploymentsRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listApiDeployments($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getApiDeployments()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.apigeeregistry.v1.Registry/ListApiDeployments', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listApiDeploymentsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->apiName('[PROJECT]', '[LOCATION]', '[API]'); + $request = (new ListApiDeploymentsRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listApiDeployments($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listApiSpecRevisionsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $apiSpecsElement = new ApiSpec(); + $apiSpecs = [ + $apiSpecsElement, + ]; + $expectedResponse = new ListApiSpecRevisionsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setApiSpecs($apiSpecs); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->apiSpecName('[PROJECT]', '[LOCATION]', '[API]', '[VERSION]', '[SPEC]'); + $request = (new ListApiSpecRevisionsRequest()) + ->setName($formattedName); + $response = $gapicClient->listApiSpecRevisions($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getApiSpecs()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.apigeeregistry.v1.Registry/ListApiSpecRevisions', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listApiSpecRevisionsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->apiSpecName('[PROJECT]', '[LOCATION]', '[API]', '[VERSION]', '[SPEC]'); + $request = (new ListApiSpecRevisionsRequest()) + ->setName($formattedName); + try { + $gapicClient->listApiSpecRevisions($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listApiSpecsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $apiSpecsElement = new ApiSpec(); + $apiSpecs = [ + $apiSpecsElement, + ]; + $expectedResponse = new ListApiSpecsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setApiSpecs($apiSpecs); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->apiVersionName('[PROJECT]', '[LOCATION]', '[API]', '[VERSION]'); + $request = (new ListApiSpecsRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listApiSpecs($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getApiSpecs()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.apigeeregistry.v1.Registry/ListApiSpecs', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listApiSpecsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->apiVersionName('[PROJECT]', '[LOCATION]', '[API]', '[VERSION]'); + $request = (new ListApiSpecsRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listApiSpecs($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listApiVersionsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $apiVersionsElement = new ApiVersion(); + $apiVersions = [ + $apiVersionsElement, + ]; + $expectedResponse = new ListApiVersionsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setApiVersions($apiVersions); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->apiName('[PROJECT]', '[LOCATION]', '[API]'); + $request = (new ListApiVersionsRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listApiVersions($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getApiVersions()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.apigeeregistry.v1.Registry/ListApiVersions', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listApiVersionsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->apiName('[PROJECT]', '[LOCATION]', '[API]'); + $request = (new ListApiVersionsRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listApiVersions($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listApisTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $apisElement = new Api(); + $apis = [ + $apisElement, + ]; + $expectedResponse = new ListApisResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setApis($apis); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListApisRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listApis($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getApis()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.apigeeregistry.v1.Registry/ListApis', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listApisExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListApisRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listApis($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listArtifactsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $artifactsElement = new Artifact(); + $artifacts = [ + $artifactsElement, + ]; + $expectedResponse = new ListArtifactsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setArtifacts($artifacts); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListArtifactsRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listArtifacts($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getArtifacts()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.apigeeregistry.v1.Registry/ListArtifacts', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listArtifactsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListArtifactsRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listArtifacts($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function replaceArtifactTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $mimeType = 'mimeType-196041627'; + $sizeBytes = 1796325715; + $hash = 'hash3195150'; + $contents = '26'; + $expectedResponse = new Artifact(); + $expectedResponse->setName($name); + $expectedResponse->setMimeType($mimeType); + $expectedResponse->setSizeBytes($sizeBytes); + $expectedResponse->setHash($hash); + $expectedResponse->setContents($contents); + $transport->addResponse($expectedResponse); + // Mock request + $artifact = new Artifact(); + $request = (new ReplaceArtifactRequest()) + ->setArtifact($artifact); + $response = $gapicClient->replaceArtifact($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.apigeeregistry.v1.Registry/ReplaceArtifact', $actualFuncCall); + $actualValue = $actualRequestObject->getArtifact(); + $this->assertProtobufEquals($artifact, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function replaceArtifactExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $artifact = new Artifact(); + $request = (new ReplaceArtifactRequest()) + ->setArtifact($artifact); + try { + $gapicClient->replaceArtifact($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function rollbackApiDeploymentTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $displayName = 'displayName1615086568'; + $description = 'description-1724546052'; + $revisionId2 = 'revisionId2-100208654'; + $apiSpecRevision = 'apiSpecRevision-1685452166'; + $endpointUri = 'endpointUri-850313278'; + $externalChannelUri = 'externalChannelUri-559177284'; + $intendedAudience = 'intendedAudience-1100067944'; + $accessGuidance = 'accessGuidance24590291'; + $expectedResponse = new ApiDeployment(); + $expectedResponse->setName($name2); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setDescription($description); + $expectedResponse->setRevisionId($revisionId2); + $expectedResponse->setApiSpecRevision($apiSpecRevision); + $expectedResponse->setEndpointUri($endpointUri); + $expectedResponse->setExternalChannelUri($externalChannelUri); + $expectedResponse->setIntendedAudience($intendedAudience); + $expectedResponse->setAccessGuidance($accessGuidance); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->apiDeploymentName('[PROJECT]', '[LOCATION]', '[API]', '[DEPLOYMENT]'); + $revisionId = 'revisionId513861631'; + $request = (new RollbackApiDeploymentRequest()) + ->setName($formattedName) + ->setRevisionId($revisionId); + $response = $gapicClient->rollbackApiDeployment($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.apigeeregistry.v1.Registry/RollbackApiDeployment', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $actualValue = $actualRequestObject->getRevisionId(); + $this->assertProtobufEquals($revisionId, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function rollbackApiDeploymentExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->apiDeploymentName('[PROJECT]', '[LOCATION]', '[API]', '[DEPLOYMENT]'); + $revisionId = 'revisionId513861631'; + $request = (new RollbackApiDeploymentRequest()) + ->setName($formattedName) + ->setRevisionId($revisionId); + try { + $gapicClient->rollbackApiDeployment($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function rollbackApiSpecTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $filename = 'filename-734768633'; + $description = 'description-1724546052'; + $revisionId2 = 'revisionId2-100208654'; + $mimeType = 'mimeType-196041627'; + $sizeBytes = 1796325715; + $hash = 'hash3195150'; + $sourceUri = 'sourceUri-1111107768'; + $contents = '26'; + $expectedResponse = new ApiSpec(); + $expectedResponse->setName($name2); + $expectedResponse->setFilename($filename); + $expectedResponse->setDescription($description); + $expectedResponse->setRevisionId($revisionId2); + $expectedResponse->setMimeType($mimeType); + $expectedResponse->setSizeBytes($sizeBytes); + $expectedResponse->setHash($hash); + $expectedResponse->setSourceUri($sourceUri); + $expectedResponse->setContents($contents); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->apiSpecName('[PROJECT]', '[LOCATION]', '[API]', '[VERSION]', '[SPEC]'); + $revisionId = 'revisionId513861631'; + $request = (new RollbackApiSpecRequest()) + ->setName($formattedName) + ->setRevisionId($revisionId); + $response = $gapicClient->rollbackApiSpec($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.apigeeregistry.v1.Registry/RollbackApiSpec', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $actualValue = $actualRequestObject->getRevisionId(); + $this->assertProtobufEquals($revisionId, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function rollbackApiSpecExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->apiSpecName('[PROJECT]', '[LOCATION]', '[API]', '[VERSION]', '[SPEC]'); + $revisionId = 'revisionId513861631'; + $request = (new RollbackApiSpecRequest()) + ->setName($formattedName) + ->setRevisionId($revisionId); + try { + $gapicClient->rollbackApiSpec($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function tagApiDeploymentRevisionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $displayName = 'displayName1615086568'; + $description = 'description-1724546052'; + $revisionId = 'revisionId513861631'; + $apiSpecRevision = 'apiSpecRevision-1685452166'; + $endpointUri = 'endpointUri-850313278'; + $externalChannelUri = 'externalChannelUri-559177284'; + $intendedAudience = 'intendedAudience-1100067944'; + $accessGuidance = 'accessGuidance24590291'; + $expectedResponse = new ApiDeployment(); + $expectedResponse->setName($name2); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setDescription($description); + $expectedResponse->setRevisionId($revisionId); + $expectedResponse->setApiSpecRevision($apiSpecRevision); + $expectedResponse->setEndpointUri($endpointUri); + $expectedResponse->setExternalChannelUri($externalChannelUri); + $expectedResponse->setIntendedAudience($intendedAudience); + $expectedResponse->setAccessGuidance($accessGuidance); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->apiDeploymentName('[PROJECT]', '[LOCATION]', '[API]', '[DEPLOYMENT]'); + $tag = 'tag114586'; + $request = (new TagApiDeploymentRevisionRequest()) + ->setName($formattedName) + ->setTag($tag); + $response = $gapicClient->tagApiDeploymentRevision($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.apigeeregistry.v1.Registry/TagApiDeploymentRevision', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $actualValue = $actualRequestObject->getTag(); + $this->assertProtobufEquals($tag, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function tagApiDeploymentRevisionExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->apiDeploymentName('[PROJECT]', '[LOCATION]', '[API]', '[DEPLOYMENT]'); + $tag = 'tag114586'; + $request = (new TagApiDeploymentRevisionRequest()) + ->setName($formattedName) + ->setTag($tag); + try { + $gapicClient->tagApiDeploymentRevision($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function tagApiSpecRevisionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $filename = 'filename-734768633'; + $description = 'description-1724546052'; + $revisionId = 'revisionId513861631'; + $mimeType = 'mimeType-196041627'; + $sizeBytes = 1796325715; + $hash = 'hash3195150'; + $sourceUri = 'sourceUri-1111107768'; + $contents = '26'; + $expectedResponse = new ApiSpec(); + $expectedResponse->setName($name2); + $expectedResponse->setFilename($filename); + $expectedResponse->setDescription($description); + $expectedResponse->setRevisionId($revisionId); + $expectedResponse->setMimeType($mimeType); + $expectedResponse->setSizeBytes($sizeBytes); + $expectedResponse->setHash($hash); + $expectedResponse->setSourceUri($sourceUri); + $expectedResponse->setContents($contents); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->apiSpecName('[PROJECT]', '[LOCATION]', '[API]', '[VERSION]', '[SPEC]'); + $tag = 'tag114586'; + $request = (new TagApiSpecRevisionRequest()) + ->setName($formattedName) + ->setTag($tag); + $response = $gapicClient->tagApiSpecRevision($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.apigeeregistry.v1.Registry/TagApiSpecRevision', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $actualValue = $actualRequestObject->getTag(); + $this->assertProtobufEquals($tag, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function tagApiSpecRevisionExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->apiSpecName('[PROJECT]', '[LOCATION]', '[API]', '[VERSION]', '[SPEC]'); + $tag = 'tag114586'; + $request = (new TagApiSpecRevisionRequest()) + ->setName($formattedName) + ->setTag($tag); + try { + $gapicClient->tagApiSpecRevision($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function updateApiTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $displayName = 'displayName1615086568'; + $description = 'description-1724546052'; + $availability = 'availability1997542747'; + $recommendedVersion = 'recommendedVersion265230068'; + $recommendedDeployment = 'recommendedDeployment1339243305'; + $expectedResponse = new Api(); + $expectedResponse->setName($name); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setDescription($description); + $expectedResponse->setAvailability($availability); + $expectedResponse->setRecommendedVersion($recommendedVersion); + $expectedResponse->setRecommendedDeployment($recommendedDeployment); + $transport->addResponse($expectedResponse); + // Mock request + $api = new Api(); + $request = (new UpdateApiRequest()) + ->setApi($api); + $response = $gapicClient->updateApi($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.apigeeregistry.v1.Registry/UpdateApi', $actualFuncCall); + $actualValue = $actualRequestObject->getApi(); + $this->assertProtobufEquals($api, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function updateApiExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $api = new Api(); + $request = (new UpdateApiRequest()) + ->setApi($api); + try { + $gapicClient->updateApi($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function updateApiDeploymentTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $displayName = 'displayName1615086568'; + $description = 'description-1724546052'; + $revisionId = 'revisionId513861631'; + $apiSpecRevision = 'apiSpecRevision-1685452166'; + $endpointUri = 'endpointUri-850313278'; + $externalChannelUri = 'externalChannelUri-559177284'; + $intendedAudience = 'intendedAudience-1100067944'; + $accessGuidance = 'accessGuidance24590291'; + $expectedResponse = new ApiDeployment(); + $expectedResponse->setName($name); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setDescription($description); + $expectedResponse->setRevisionId($revisionId); + $expectedResponse->setApiSpecRevision($apiSpecRevision); + $expectedResponse->setEndpointUri($endpointUri); + $expectedResponse->setExternalChannelUri($externalChannelUri); + $expectedResponse->setIntendedAudience($intendedAudience); + $expectedResponse->setAccessGuidance($accessGuidance); + $transport->addResponse($expectedResponse); + // Mock request + $apiDeployment = new ApiDeployment(); + $request = (new UpdateApiDeploymentRequest()) + ->setApiDeployment($apiDeployment); + $response = $gapicClient->updateApiDeployment($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.apigeeregistry.v1.Registry/UpdateApiDeployment', $actualFuncCall); + $actualValue = $actualRequestObject->getApiDeployment(); + $this->assertProtobufEquals($apiDeployment, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function updateApiDeploymentExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $apiDeployment = new ApiDeployment(); + $request = (new UpdateApiDeploymentRequest()) + ->setApiDeployment($apiDeployment); + try { + $gapicClient->updateApiDeployment($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function updateApiSpecTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $filename = 'filename-734768633'; + $description = 'description-1724546052'; + $revisionId = 'revisionId513861631'; + $mimeType = 'mimeType-196041627'; + $sizeBytes = 1796325715; + $hash = 'hash3195150'; + $sourceUri = 'sourceUri-1111107768'; + $contents = '26'; + $expectedResponse = new ApiSpec(); + $expectedResponse->setName($name); + $expectedResponse->setFilename($filename); + $expectedResponse->setDescription($description); + $expectedResponse->setRevisionId($revisionId); + $expectedResponse->setMimeType($mimeType); + $expectedResponse->setSizeBytes($sizeBytes); + $expectedResponse->setHash($hash); + $expectedResponse->setSourceUri($sourceUri); + $expectedResponse->setContents($contents); + $transport->addResponse($expectedResponse); + // Mock request + $apiSpec = new ApiSpec(); + $request = (new UpdateApiSpecRequest()) + ->setApiSpec($apiSpec); + $response = $gapicClient->updateApiSpec($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.apigeeregistry.v1.Registry/UpdateApiSpec', $actualFuncCall); + $actualValue = $actualRequestObject->getApiSpec(); + $this->assertProtobufEquals($apiSpec, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function updateApiSpecExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $apiSpec = new ApiSpec(); + $request = (new UpdateApiSpecRequest()) + ->setApiSpec($apiSpec); + try { + $gapicClient->updateApiSpec($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function updateApiVersionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $displayName = 'displayName1615086568'; + $description = 'description-1724546052'; + $state = 'state109757585'; + $expectedResponse = new ApiVersion(); + $expectedResponse->setName($name); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setDescription($description); + $expectedResponse->setState($state); + $transport->addResponse($expectedResponse); + // Mock request + $apiVersion = new ApiVersion(); + $request = (new UpdateApiVersionRequest()) + ->setApiVersion($apiVersion); + $response = $gapicClient->updateApiVersion($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.apigeeregistry.v1.Registry/UpdateApiVersion', $actualFuncCall); + $actualValue = $actualRequestObject->getApiVersion(); + $this->assertProtobufEquals($apiVersion, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function updateApiVersionExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $apiVersion = new ApiVersion(); + $request = (new UpdateApiVersionRequest()) + ->setApiVersion($apiVersion); + try { + $gapicClient->updateApiVersion($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getLocationTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $locationId = 'locationId552319461'; + $displayName = 'displayName1615086568'; + $expectedResponse = new Location(); + $expectedResponse->setName($name2); + $expectedResponse->setLocationId($locationId); + $expectedResponse->setDisplayName($displayName); + $transport->addResponse($expectedResponse); + $request = new GetLocationRequest(); + $response = $gapicClient->getLocation($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.location.Locations/GetLocation', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getLocationExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + $request = new GetLocationRequest(); + try { + $gapicClient->getLocation($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listLocationsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $locationsElement = new Location(); + $locations = [ + $locationsElement, + ]; + $expectedResponse = new ListLocationsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setLocations($locations); + $transport->addResponse($expectedResponse); + $request = new ListLocationsRequest(); + $response = $gapicClient->listLocations($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getLocations()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.location.Locations/ListLocations', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listLocationsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + $request = new ListLocationsRequest(); + try { + $gapicClient->listLocations($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getIamPolicyTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $version = 351608024; + $etag = '21'; + $expectedResponse = new Policy(); + $expectedResponse->setVersion($version); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + $response = $gapicClient->getIamPolicy($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.iam.v1.IAMPolicy/GetIamPolicy', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getIamPolicyExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $resource = 'resource-341064690'; + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + try { + $gapicClient->getIamPolicy($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function setIamPolicyTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $version = 351608024; + $etag = '21'; + $expectedResponse = new Policy(); + $expectedResponse->setVersion($version); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $policy = new Policy(); + $request = (new SetIamPolicyRequest()) + ->setResource($resource) + ->setPolicy($policy); + $response = $gapicClient->setIamPolicy($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.iam.v1.IAMPolicy/SetIamPolicy', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $actualValue = $actualRequestObject->getPolicy(); + $this->assertProtobufEquals($policy, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function setIamPolicyExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $resource = 'resource-341064690'; + $policy = new Policy(); + $request = (new SetIamPolicyRequest()) + ->setResource($resource) + ->setPolicy($policy); + try { + $gapicClient->setIamPolicy($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function testIamPermissionsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new TestIamPermissionsResponse(); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $permissions = []; + $request = (new TestIamPermissionsRequest()) + ->setResource($resource) + ->setPermissions($permissions); + $response = $gapicClient->testIamPermissions($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.iam.v1.IAMPolicy/TestIamPermissions', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $actualValue = $actualRequestObject->getPermissions(); + $this->assertProtobufEquals($permissions, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function testIamPermissionsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $resource = 'resource-341064690'; + $permissions = []; + $request = (new TestIamPermissionsRequest()) + ->setResource($resource) + ->setPermissions($permissions); + try { + $gapicClient->testIamPermissions($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createApiAsyncTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $displayName = 'displayName1615086568'; + $description = 'description-1724546052'; + $availability = 'availability1997542747'; + $recommendedVersion = 'recommendedVersion265230068'; + $recommendedDeployment = 'recommendedDeployment1339243305'; + $expectedResponse = new Api(); + $expectedResponse->setName($name); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setDescription($description); + $expectedResponse->setAvailability($availability); + $expectedResponse->setRecommendedVersion($recommendedVersion); + $expectedResponse->setRecommendedDeployment($recommendedDeployment); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $api = new Api(); + $apiId = 'apiId-1411282592'; + $request = (new CreateApiRequest()) + ->setParent($formattedParent) + ->setApi($api) + ->setApiId($apiId); + $response = $gapicClient->createApiAsync($request)->wait(); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.apigeeregistry.v1.Registry/CreateApi', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getApi(); + $this->assertProtobufEquals($api, $actualValue); + $actualValue = $actualRequestObject->getApiId(); + $this->assertProtobufEquals($apiId, $actualValue); + $this->assertTrue($transport->isExhausted()); + } +} diff --git a/BareMetalSolution/samples/V2/BareMetalSolutionClient/detach_lun.php b/BareMetalSolution/samples/V2/BareMetalSolutionClient/detach_lun.php index e1558bb7fd1a..0c6d33e02c83 100644 --- a/BareMetalSolution/samples/V2/BareMetalSolutionClient/detach_lun.php +++ b/BareMetalSolution/samples/V2/BareMetalSolutionClient/detach_lun.php @@ -25,7 +25,8 @@ // [START baremetalsolution_v2_generated_BareMetalSolution_DetachLun_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\BareMetalSolution\V2\BareMetalSolutionClient; +use Google\Cloud\BareMetalSolution\V2\Client\BareMetalSolutionClient; +use Google\Cloud\BareMetalSolution\V2\DetachLunRequest; use Google\Cloud\BareMetalSolution\V2\Instance; use Google\Rpc\Status; @@ -42,10 +43,15 @@ function detach_lun_sample(string $formattedInstance, string $formattedLun): voi // Create a client. $bareMetalSolutionClient = new BareMetalSolutionClient(); + // Prepare the request message. + $request = (new DetachLunRequest()) + ->setInstance($formattedInstance) + ->setLun($formattedLun); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $bareMetalSolutionClient->detachLun($formattedInstance, $formattedLun); + $response = $bareMetalSolutionClient->detachLun($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/BareMetalSolution/samples/V2/BareMetalSolutionClient/get_instance.php b/BareMetalSolution/samples/V2/BareMetalSolutionClient/get_instance.php index 9c1afdfd573e..48c31fef99b6 100644 --- a/BareMetalSolution/samples/V2/BareMetalSolutionClient/get_instance.php +++ b/BareMetalSolution/samples/V2/BareMetalSolutionClient/get_instance.php @@ -24,7 +24,8 @@ // [START baremetalsolution_v2_generated_BareMetalSolution_GetInstance_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BareMetalSolution\V2\BareMetalSolutionClient; +use Google\Cloud\BareMetalSolution\V2\Client\BareMetalSolutionClient; +use Google\Cloud\BareMetalSolution\V2\GetInstanceRequest; use Google\Cloud\BareMetalSolution\V2\Instance; /** @@ -38,10 +39,14 @@ function get_instance_sample(string $formattedName): void // Create a client. $bareMetalSolutionClient = new BareMetalSolutionClient(); + // Prepare the request message. + $request = (new GetInstanceRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var Instance $response */ - $response = $bareMetalSolutionClient->getInstance($formattedName); + $response = $bareMetalSolutionClient->getInstance($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BareMetalSolution/samples/V2/BareMetalSolutionClient/get_lun.php b/BareMetalSolution/samples/V2/BareMetalSolutionClient/get_lun.php index 7b7fa306ff9e..a63216883ffa 100644 --- a/BareMetalSolution/samples/V2/BareMetalSolutionClient/get_lun.php +++ b/BareMetalSolution/samples/V2/BareMetalSolutionClient/get_lun.php @@ -24,7 +24,8 @@ // [START baremetalsolution_v2_generated_BareMetalSolution_GetLun_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BareMetalSolution\V2\BareMetalSolutionClient; +use Google\Cloud\BareMetalSolution\V2\Client\BareMetalSolutionClient; +use Google\Cloud\BareMetalSolution\V2\GetLunRequest; use Google\Cloud\BareMetalSolution\V2\Lun; /** @@ -38,10 +39,14 @@ function get_lun_sample(string $formattedName): void // Create a client. $bareMetalSolutionClient = new BareMetalSolutionClient(); + // Prepare the request message. + $request = (new GetLunRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var Lun $response */ - $response = $bareMetalSolutionClient->getLun($formattedName); + $response = $bareMetalSolutionClient->getLun($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BareMetalSolution/samples/V2/BareMetalSolutionClient/get_network.php b/BareMetalSolution/samples/V2/BareMetalSolutionClient/get_network.php index 6608192fa26d..d2b6e29b05c9 100644 --- a/BareMetalSolution/samples/V2/BareMetalSolutionClient/get_network.php +++ b/BareMetalSolution/samples/V2/BareMetalSolutionClient/get_network.php @@ -24,7 +24,8 @@ // [START baremetalsolution_v2_generated_BareMetalSolution_GetNetwork_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BareMetalSolution\V2\BareMetalSolutionClient; +use Google\Cloud\BareMetalSolution\V2\Client\BareMetalSolutionClient; +use Google\Cloud\BareMetalSolution\V2\GetNetworkRequest; use Google\Cloud\BareMetalSolution\V2\Network; /** @@ -38,10 +39,14 @@ function get_network_sample(string $formattedName): void // Create a client. $bareMetalSolutionClient = new BareMetalSolutionClient(); + // Prepare the request message. + $request = (new GetNetworkRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var Network $response */ - $response = $bareMetalSolutionClient->getNetwork($formattedName); + $response = $bareMetalSolutionClient->getNetwork($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BareMetalSolution/samples/V2/BareMetalSolutionClient/get_nfs_share.php b/BareMetalSolution/samples/V2/BareMetalSolutionClient/get_nfs_share.php index 7f08b24f46ed..ef5c5a017680 100644 --- a/BareMetalSolution/samples/V2/BareMetalSolutionClient/get_nfs_share.php +++ b/BareMetalSolution/samples/V2/BareMetalSolutionClient/get_nfs_share.php @@ -24,7 +24,8 @@ // [START baremetalsolution_v2_generated_BareMetalSolution_GetNfsShare_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BareMetalSolution\V2\BareMetalSolutionClient; +use Google\Cloud\BareMetalSolution\V2\Client\BareMetalSolutionClient; +use Google\Cloud\BareMetalSolution\V2\GetNfsShareRequest; use Google\Cloud\BareMetalSolution\V2\NfsShare; /** @@ -38,10 +39,14 @@ function get_nfs_share_sample(string $formattedName): void // Create a client. $bareMetalSolutionClient = new BareMetalSolutionClient(); + // Prepare the request message. + $request = (new GetNfsShareRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var NfsShare $response */ - $response = $bareMetalSolutionClient->getNfsShare($formattedName); + $response = $bareMetalSolutionClient->getNfsShare($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BareMetalSolution/samples/V2/BareMetalSolutionClient/get_volume.php b/BareMetalSolution/samples/V2/BareMetalSolutionClient/get_volume.php index 58cb053c27f3..2d648eda69b4 100644 --- a/BareMetalSolution/samples/V2/BareMetalSolutionClient/get_volume.php +++ b/BareMetalSolution/samples/V2/BareMetalSolutionClient/get_volume.php @@ -24,7 +24,8 @@ // [START baremetalsolution_v2_generated_BareMetalSolution_GetVolume_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BareMetalSolution\V2\BareMetalSolutionClient; +use Google\Cloud\BareMetalSolution\V2\Client\BareMetalSolutionClient; +use Google\Cloud\BareMetalSolution\V2\GetVolumeRequest; use Google\Cloud\BareMetalSolution\V2\Volume; /** @@ -38,10 +39,14 @@ function get_volume_sample(string $formattedName): void // Create a client. $bareMetalSolutionClient = new BareMetalSolutionClient(); + // Prepare the request message. + $request = (new GetVolumeRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var Volume $response */ - $response = $bareMetalSolutionClient->getVolume($formattedName); + $response = $bareMetalSolutionClient->getVolume($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BareMetalSolution/samples/V2/BareMetalSolutionClient/list_instances.php b/BareMetalSolution/samples/V2/BareMetalSolutionClient/list_instances.php index 470e02c36b98..37d1bc492499 100644 --- a/BareMetalSolution/samples/V2/BareMetalSolutionClient/list_instances.php +++ b/BareMetalSolution/samples/V2/BareMetalSolutionClient/list_instances.php @@ -25,8 +25,9 @@ // [START baremetalsolution_v2_generated_BareMetalSolution_ListInstances_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; -use Google\Cloud\BareMetalSolution\V2\BareMetalSolutionClient; +use Google\Cloud\BareMetalSolution\V2\Client\BareMetalSolutionClient; use Google\Cloud\BareMetalSolution\V2\Instance; +use Google\Cloud\BareMetalSolution\V2\ListInstancesRequest; /** * List servers in a given project and location. @@ -39,10 +40,14 @@ function list_instances_sample(string $formattedParent): void // Create a client. $bareMetalSolutionClient = new BareMetalSolutionClient(); + // Prepare the request message. + $request = (new ListInstancesRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $bareMetalSolutionClient->listInstances($formattedParent); + $response = $bareMetalSolutionClient->listInstances($request); /** @var Instance $element */ foreach ($response as $element) { diff --git a/BareMetalSolution/samples/V2/BareMetalSolutionClient/list_luns.php b/BareMetalSolution/samples/V2/BareMetalSolutionClient/list_luns.php index 73fab67760b8..3d4d2762b84a 100644 --- a/BareMetalSolution/samples/V2/BareMetalSolutionClient/list_luns.php +++ b/BareMetalSolution/samples/V2/BareMetalSolutionClient/list_luns.php @@ -25,7 +25,8 @@ // [START baremetalsolution_v2_generated_BareMetalSolution_ListLuns_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; -use Google\Cloud\BareMetalSolution\V2\BareMetalSolutionClient; +use Google\Cloud\BareMetalSolution\V2\Client\BareMetalSolutionClient; +use Google\Cloud\BareMetalSolution\V2\ListLunsRequest; use Google\Cloud\BareMetalSolution\V2\Lun; /** @@ -39,10 +40,14 @@ function list_luns_sample(string $formattedParent): void // Create a client. $bareMetalSolutionClient = new BareMetalSolutionClient(); + // Prepare the request message. + $request = (new ListLunsRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $bareMetalSolutionClient->listLuns($formattedParent); + $response = $bareMetalSolutionClient->listLuns($request); /** @var Lun $element */ foreach ($response as $element) { diff --git a/BareMetalSolution/samples/V2/BareMetalSolutionClient/list_network_usage.php b/BareMetalSolution/samples/V2/BareMetalSolutionClient/list_network_usage.php index 821d9fae467d..c19e50064006 100644 --- a/BareMetalSolution/samples/V2/BareMetalSolutionClient/list_network_usage.php +++ b/BareMetalSolution/samples/V2/BareMetalSolutionClient/list_network_usage.php @@ -24,7 +24,8 @@ // [START baremetalsolution_v2_generated_BareMetalSolution_ListNetworkUsage_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BareMetalSolution\V2\BareMetalSolutionClient; +use Google\Cloud\BareMetalSolution\V2\Client\BareMetalSolutionClient; +use Google\Cloud\BareMetalSolution\V2\ListNetworkUsageRequest; use Google\Cloud\BareMetalSolution\V2\ListNetworkUsageResponse; /** @@ -39,10 +40,14 @@ function list_network_usage_sample(string $formattedLocation): void // Create a client. $bareMetalSolutionClient = new BareMetalSolutionClient(); + // Prepare the request message. + $request = (new ListNetworkUsageRequest()) + ->setLocation($formattedLocation); + // Call the API and handle any network failures. try { /** @var ListNetworkUsageResponse $response */ - $response = $bareMetalSolutionClient->listNetworkUsage($formattedLocation); + $response = $bareMetalSolutionClient->listNetworkUsage($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BareMetalSolution/samples/V2/BareMetalSolutionClient/list_networks.php b/BareMetalSolution/samples/V2/BareMetalSolutionClient/list_networks.php index 13a53bce96eb..2a587ec841b1 100644 --- a/BareMetalSolution/samples/V2/BareMetalSolutionClient/list_networks.php +++ b/BareMetalSolution/samples/V2/BareMetalSolutionClient/list_networks.php @@ -25,7 +25,8 @@ // [START baremetalsolution_v2_generated_BareMetalSolution_ListNetworks_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; -use Google\Cloud\BareMetalSolution\V2\BareMetalSolutionClient; +use Google\Cloud\BareMetalSolution\V2\Client\BareMetalSolutionClient; +use Google\Cloud\BareMetalSolution\V2\ListNetworksRequest; use Google\Cloud\BareMetalSolution\V2\Network; /** @@ -39,10 +40,14 @@ function list_networks_sample(string $formattedParent): void // Create a client. $bareMetalSolutionClient = new BareMetalSolutionClient(); + // Prepare the request message. + $request = (new ListNetworksRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $bareMetalSolutionClient->listNetworks($formattedParent); + $response = $bareMetalSolutionClient->listNetworks($request); /** @var Network $element */ foreach ($response as $element) { diff --git a/BareMetalSolution/samples/V2/BareMetalSolutionClient/list_nfs_shares.php b/BareMetalSolution/samples/V2/BareMetalSolutionClient/list_nfs_shares.php index a976dd0e41a6..099316c04aab 100644 --- a/BareMetalSolution/samples/V2/BareMetalSolutionClient/list_nfs_shares.php +++ b/BareMetalSolution/samples/V2/BareMetalSolutionClient/list_nfs_shares.php @@ -25,7 +25,8 @@ // [START baremetalsolution_v2_generated_BareMetalSolution_ListNfsShares_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; -use Google\Cloud\BareMetalSolution\V2\BareMetalSolutionClient; +use Google\Cloud\BareMetalSolution\V2\Client\BareMetalSolutionClient; +use Google\Cloud\BareMetalSolution\V2\ListNfsSharesRequest; use Google\Cloud\BareMetalSolution\V2\NfsShare; /** @@ -39,10 +40,14 @@ function list_nfs_shares_sample(string $formattedParent): void // Create a client. $bareMetalSolutionClient = new BareMetalSolutionClient(); + // Prepare the request message. + $request = (new ListNfsSharesRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $bareMetalSolutionClient->listNfsShares($formattedParent); + $response = $bareMetalSolutionClient->listNfsShares($request); /** @var NfsShare $element */ foreach ($response as $element) { diff --git a/BareMetalSolution/samples/V2/BareMetalSolutionClient/list_volumes.php b/BareMetalSolution/samples/V2/BareMetalSolutionClient/list_volumes.php index 37dfac28bcfe..ff93f6dc6f3e 100644 --- a/BareMetalSolution/samples/V2/BareMetalSolutionClient/list_volumes.php +++ b/BareMetalSolution/samples/V2/BareMetalSolutionClient/list_volumes.php @@ -25,7 +25,8 @@ // [START baremetalsolution_v2_generated_BareMetalSolution_ListVolumes_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; -use Google\Cloud\BareMetalSolution\V2\BareMetalSolutionClient; +use Google\Cloud\BareMetalSolution\V2\Client\BareMetalSolutionClient; +use Google\Cloud\BareMetalSolution\V2\ListVolumesRequest; use Google\Cloud\BareMetalSolution\V2\Volume; /** @@ -39,10 +40,14 @@ function list_volumes_sample(string $formattedParent): void // Create a client. $bareMetalSolutionClient = new BareMetalSolutionClient(); + // Prepare the request message. + $request = (new ListVolumesRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $bareMetalSolutionClient->listVolumes($formattedParent); + $response = $bareMetalSolutionClient->listVolumes($request); /** @var Volume $element */ foreach ($response as $element) { diff --git a/BareMetalSolution/samples/V2/BareMetalSolutionClient/reset_instance.php b/BareMetalSolution/samples/V2/BareMetalSolutionClient/reset_instance.php index 6de1ccbebc81..ca2f975dc539 100644 --- a/BareMetalSolution/samples/V2/BareMetalSolutionClient/reset_instance.php +++ b/BareMetalSolution/samples/V2/BareMetalSolutionClient/reset_instance.php @@ -25,7 +25,8 @@ // [START baremetalsolution_v2_generated_BareMetalSolution_ResetInstance_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\BareMetalSolution\V2\BareMetalSolutionClient; +use Google\Cloud\BareMetalSolution\V2\Client\BareMetalSolutionClient; +use Google\Cloud\BareMetalSolution\V2\ResetInstanceRequest; use Google\Cloud\BareMetalSolution\V2\ResetInstanceResponse; use Google\Rpc\Status; @@ -41,10 +42,14 @@ function reset_instance_sample(string $formattedName): void // Create a client. $bareMetalSolutionClient = new BareMetalSolutionClient(); + // Prepare the request message. + $request = (new ResetInstanceRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $bareMetalSolutionClient->resetInstance($formattedName); + $response = $bareMetalSolutionClient->resetInstance($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/BareMetalSolution/samples/V2/BareMetalSolutionClient/resize_volume.php b/BareMetalSolution/samples/V2/BareMetalSolutionClient/resize_volume.php index ae0428c73090..b70e3c59c86c 100644 --- a/BareMetalSolution/samples/V2/BareMetalSolutionClient/resize_volume.php +++ b/BareMetalSolution/samples/V2/BareMetalSolutionClient/resize_volume.php @@ -25,7 +25,8 @@ // [START baremetalsolution_v2_generated_BareMetalSolution_ResizeVolume_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\BareMetalSolution\V2\BareMetalSolutionClient; +use Google\Cloud\BareMetalSolution\V2\Client\BareMetalSolutionClient; +use Google\Cloud\BareMetalSolution\V2\ResizeVolumeRequest; use Google\Cloud\BareMetalSolution\V2\Volume; use Google\Rpc\Status; @@ -40,10 +41,14 @@ function resize_volume_sample(string $formattedVolume): void // Create a client. $bareMetalSolutionClient = new BareMetalSolutionClient(); + // Prepare the request message. + $request = (new ResizeVolumeRequest()) + ->setVolume($formattedVolume); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $bareMetalSolutionClient->resizeVolume($formattedVolume); + $response = $bareMetalSolutionClient->resizeVolume($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/BareMetalSolution/samples/V2/BareMetalSolutionClient/start_instance.php b/BareMetalSolution/samples/V2/BareMetalSolutionClient/start_instance.php index 9d0fc4aae848..575ea412e818 100644 --- a/BareMetalSolution/samples/V2/BareMetalSolutionClient/start_instance.php +++ b/BareMetalSolution/samples/V2/BareMetalSolutionClient/start_instance.php @@ -25,7 +25,8 @@ // [START baremetalsolution_v2_generated_BareMetalSolution_StartInstance_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\BareMetalSolution\V2\BareMetalSolutionClient; +use Google\Cloud\BareMetalSolution\V2\Client\BareMetalSolutionClient; +use Google\Cloud\BareMetalSolution\V2\StartInstanceRequest; use Google\Cloud\BareMetalSolution\V2\StartInstanceResponse; use Google\Rpc\Status; @@ -40,10 +41,14 @@ function start_instance_sample(string $formattedName): void // Create a client. $bareMetalSolutionClient = new BareMetalSolutionClient(); + // Prepare the request message. + $request = (new StartInstanceRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $bareMetalSolutionClient->startInstance($formattedName); + $response = $bareMetalSolutionClient->startInstance($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/BareMetalSolution/samples/V2/BareMetalSolutionClient/stop_instance.php b/BareMetalSolution/samples/V2/BareMetalSolutionClient/stop_instance.php index 98838551484b..2d53458a921f 100644 --- a/BareMetalSolution/samples/V2/BareMetalSolutionClient/stop_instance.php +++ b/BareMetalSolution/samples/V2/BareMetalSolutionClient/stop_instance.php @@ -25,7 +25,8 @@ // [START baremetalsolution_v2_generated_BareMetalSolution_StopInstance_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\BareMetalSolution\V2\BareMetalSolutionClient; +use Google\Cloud\BareMetalSolution\V2\Client\BareMetalSolutionClient; +use Google\Cloud\BareMetalSolution\V2\StopInstanceRequest; use Google\Cloud\BareMetalSolution\V2\StopInstanceResponse; use Google\Rpc\Status; @@ -40,10 +41,14 @@ function stop_instance_sample(string $formattedName): void // Create a client. $bareMetalSolutionClient = new BareMetalSolutionClient(); + // Prepare the request message. + $request = (new StopInstanceRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $bareMetalSolutionClient->stopInstance($formattedName); + $response = $bareMetalSolutionClient->stopInstance($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/BareMetalSolution/samples/V2/BareMetalSolutionClient/update_instance.php b/BareMetalSolution/samples/V2/BareMetalSolutionClient/update_instance.php index 167e7965f5a8..61d2289e3118 100644 --- a/BareMetalSolution/samples/V2/BareMetalSolutionClient/update_instance.php +++ b/BareMetalSolution/samples/V2/BareMetalSolutionClient/update_instance.php @@ -25,8 +25,9 @@ // [START baremetalsolution_v2_generated_BareMetalSolution_UpdateInstance_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\BareMetalSolution\V2\BareMetalSolutionClient; +use Google\Cloud\BareMetalSolution\V2\Client\BareMetalSolutionClient; use Google\Cloud\BareMetalSolution\V2\Instance; +use Google\Cloud\BareMetalSolution\V2\UpdateInstanceRequest; use Google\Rpc\Status; /** @@ -43,13 +44,15 @@ function update_instance_sample(): void // Create a client. $bareMetalSolutionClient = new BareMetalSolutionClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $instance = new Instance(); + $request = (new UpdateInstanceRequest()) + ->setInstance($instance); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $bareMetalSolutionClient->updateInstance($instance); + $response = $bareMetalSolutionClient->updateInstance($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/BareMetalSolution/samples/V2/BareMetalSolutionClient/update_network.php b/BareMetalSolution/samples/V2/BareMetalSolutionClient/update_network.php index dad0ff6cce81..b5ef51b12583 100644 --- a/BareMetalSolution/samples/V2/BareMetalSolutionClient/update_network.php +++ b/BareMetalSolution/samples/V2/BareMetalSolutionClient/update_network.php @@ -25,8 +25,9 @@ // [START baremetalsolution_v2_generated_BareMetalSolution_UpdateNetwork_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\BareMetalSolution\V2\BareMetalSolutionClient; +use Google\Cloud\BareMetalSolution\V2\Client\BareMetalSolutionClient; use Google\Cloud\BareMetalSolution\V2\Network; +use Google\Cloud\BareMetalSolution\V2\UpdateNetworkRequest; use Google\Rpc\Status; /** @@ -43,13 +44,15 @@ function update_network_sample(): void // Create a client. $bareMetalSolutionClient = new BareMetalSolutionClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $network = new Network(); + $request = (new UpdateNetworkRequest()) + ->setNetwork($network); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $bareMetalSolutionClient->updateNetwork($network); + $response = $bareMetalSolutionClient->updateNetwork($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/BareMetalSolution/samples/V2/BareMetalSolutionClient/update_nfs_share.php b/BareMetalSolution/samples/V2/BareMetalSolutionClient/update_nfs_share.php index e07dce96ca71..46e316450ed6 100644 --- a/BareMetalSolution/samples/V2/BareMetalSolutionClient/update_nfs_share.php +++ b/BareMetalSolution/samples/V2/BareMetalSolutionClient/update_nfs_share.php @@ -25,8 +25,9 @@ // [START baremetalsolution_v2_generated_BareMetalSolution_UpdateNfsShare_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\BareMetalSolution\V2\BareMetalSolutionClient; +use Google\Cloud\BareMetalSolution\V2\Client\BareMetalSolutionClient; use Google\Cloud\BareMetalSolution\V2\NfsShare; +use Google\Cloud\BareMetalSolution\V2\UpdateNfsShareRequest; use Google\Rpc\Status; /** @@ -43,13 +44,15 @@ function update_nfs_share_sample(): void // Create a client. $bareMetalSolutionClient = new BareMetalSolutionClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $nfsShare = new NfsShare(); + $request = (new UpdateNfsShareRequest()) + ->setNfsShare($nfsShare); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $bareMetalSolutionClient->updateNfsShare($nfsShare); + $response = $bareMetalSolutionClient->updateNfsShare($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/BareMetalSolution/samples/V2/BareMetalSolutionClient/update_volume.php b/BareMetalSolution/samples/V2/BareMetalSolutionClient/update_volume.php index fc820199694a..66065b9c3b7d 100644 --- a/BareMetalSolution/samples/V2/BareMetalSolutionClient/update_volume.php +++ b/BareMetalSolution/samples/V2/BareMetalSolutionClient/update_volume.php @@ -25,7 +25,8 @@ // [START baremetalsolution_v2_generated_BareMetalSolution_UpdateVolume_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\BareMetalSolution\V2\BareMetalSolutionClient; +use Google\Cloud\BareMetalSolution\V2\Client\BareMetalSolutionClient; +use Google\Cloud\BareMetalSolution\V2\UpdateVolumeRequest; use Google\Cloud\BareMetalSolution\V2\Volume; use Google\Rpc\Status; @@ -43,13 +44,15 @@ function update_volume_sample(): void // Create a client. $bareMetalSolutionClient = new BareMetalSolutionClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $volume = new Volume(); + $request = (new UpdateVolumeRequest()) + ->setVolume($volume); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $bareMetalSolutionClient->updateVolume($volume); + $response = $bareMetalSolutionClient->updateVolume($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/BareMetalSolution/src/V2/Client/BareMetalSolutionClient.php b/BareMetalSolution/src/V2/Client/BareMetalSolutionClient.php new file mode 100644 index 000000000000..7e5ecbfe0137 --- /dev/null +++ b/BareMetalSolution/src/V2/Client/BareMetalSolutionClient.php @@ -0,0 +1,40 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/bare_metal_solution_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/bare_metal_solution_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/bare_metal_solution_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/bare_metal_solution_rest_client_config.php', + ], + ], + ]; + } + + /** + * Return an OperationsClient object with the same endpoint as $this. + * + * @return OperationsClient + */ + public function getOperationsClient() + { + return $this->operationsClient; + } + + /** + * Resume an existing long running operation that was previously started by a long + * running API method. If $methodName is not provided, or does not match a long + * running API method, then the operation can still be resumed, but the + * OperationResponse object will not deserialize the final response. + * + * @param string $operationName The name of the long running operation + * @param string $methodName The name of the method used to start the operation + * + * @return OperationResponse + */ + public function resumeOperation($operationName, $methodName = null) + { + $options = isset($this->descriptors[$methodName]['longRunning']) ? $this->descriptors[$methodName]['longRunning'] : []; + $operation = new OperationResponse($operationName, $this->getOperationsClient(), $options); + $operation->reload(); + return $operation; + } + + /** + * Formats a string containing the fully-qualified path to represent a instance + * resource. + * + * @param string $project + * @param string $location + * @param string $instance + * + * @return string The formatted instance resource. + */ + public static function instanceName(string $project, string $location, string $instance): string + { + return self::getPathTemplate('instance')->render([ + 'project' => $project, + 'location' => $location, + 'instance' => $instance, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a location + * resource. + * + * @param string $project + * @param string $location + * + * @return string The formatted location resource. + */ + public static function locationName(string $project, string $location): string + { + return self::getPathTemplate('location')->render([ + 'project' => $project, + 'location' => $location, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a lun + * resource. + * + * @param string $project + * @param string $location + * @param string $volume + * @param string $lun + * + * @return string The formatted lun resource. + */ + public static function lunName(string $project, string $location, string $volume, string $lun): string + { + return self::getPathTemplate('lun')->render([ + 'project' => $project, + 'location' => $location, + 'volume' => $volume, + 'lun' => $lun, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a nfs_share + * resource. + * + * @param string $project + * @param string $location + * @param string $nfsShare + * + * @return string The formatted nfs_share resource. + */ + public static function nFSShareName(string $project, string $location, string $nfsShare): string + { + return self::getPathTemplate('nFSShare')->render([ + 'project' => $project, + 'location' => $location, + 'nfs_share' => $nfsShare, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a network + * resource. + * + * @param string $project + * @param string $location + * @param string $network + * + * @return string The formatted network resource. + */ + public static function networkName(string $project, string $location, string $network): string + { + return self::getPathTemplate('network')->render([ + 'project' => $project, + 'location' => $location, + 'network' => $network, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a + * server_network_template resource. + * + * @param string $project + * @param string $location + * @param string $serverNetworkTemplate + * + * @return string The formatted server_network_template resource. + */ + public static function serverNetworkTemplateName(string $project, string $location, string $serverNetworkTemplate): string + { + return self::getPathTemplate('serverNetworkTemplate')->render([ + 'project' => $project, + 'location' => $location, + 'server_network_template' => $serverNetworkTemplate, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a volume + * resource. + * + * @param string $project + * @param string $location + * @param string $volume + * + * @return string The formatted volume resource. + */ + public static function volumeName(string $project, string $location, string $volume): string + { + return self::getPathTemplate('volume')->render([ + 'project' => $project, + 'location' => $location, + 'volume' => $volume, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * Template: Pattern + * - instance: projects/{project}/locations/{location}/instances/{instance} + * - location: projects/{project}/locations/{location} + * - lun: projects/{project}/locations/{location}/volumes/{volume}/luns/{lun} + * - nFSShare: projects/{project}/locations/{location}/nfsShares/{nfs_share} + * - network: projects/{project}/locations/{location}/networks/{network} + * - serverNetworkTemplate: projects/{project}/locations/{location}/serverNetworkTemplate/{server_network_template} + * - volume: projects/{project}/locations/{location}/volumes/{volume} + * + * The optional $template argument can be supplied to specify a particular pattern, + * and must match one of the templates listed above. If no $template argument is + * provided, or if the $template argument does not match one of the templates + * listed, then parseName will check each of the supported templates, and return + * the first match. + * + * @param string $formattedName The formatted name string + * @param string $template Optional name of template to match + * + * @return array An associative array from name component IDs to component values. + * + * @throws ValidationException If $formattedName could not be matched. + */ + public static function parseName(string $formattedName, string $template = null): array + { + return self::parseFormattedName($formattedName, $template); + } + + /** + * Constructor. + * + * @param array $options { + * Optional. Options for configuring the service API wrapper. + * + * @type string $apiEndpoint + * The address of the API remote host. May optionally include the port, formatted + * as ":". Default 'baremetalsolution.googleapis.com:443'. + * @type string|array|FetchAuthTokenInterface|CredentialsWrapper $credentials + * The credentials to be used by the client to authorize API calls. This option + * accepts either a path to a credentials file, or a decoded credentials file as a + * PHP array. + * *Advanced usage*: In addition, this option can also accept a pre-constructed + * {@see \Google\Auth\FetchAuthTokenInterface} object or + * {@see \Google\ApiCore\CredentialsWrapper} object. Note that when one of these + * objects are provided, any settings in $credentialsConfig will be ignored. + * @type array $credentialsConfig + * Options used to configure credentials, including auth token caching, for the + * client. For a full list of supporting configuration options, see + * {@see \Google\ApiCore\CredentialsWrapper::build()} . + * @type bool $disableRetries + * Determines whether or not retries defined by the client configuration should be + * disabled. Defaults to `false`. + * @type string|array $clientConfig + * Client method configuration, including retry settings. This option can be either + * a path to a JSON file, or a PHP array containing the decoded JSON data. By + * default this settings points to the default client config file, which is + * provided in the resources folder. + * @type string|TransportInterface $transport + * The transport used for executing network requests. May be either the string + * `rest` or `grpc`. Defaults to `grpc` if gRPC support is detected on the system. + * *Advanced usage*: Additionally, it is possible to pass in an already + * instantiated {@see \Google\ApiCore\Transport\TransportInterface} object. Note + * that when this object is provided, any settings in $transportConfig, and any + * $apiEndpoint setting, will be ignored. + * @type array $transportConfig + * Configuration options that will be used to construct the transport. Options for + * each supported transport type should be passed in a key for that transport. For + * example: + * $transportConfig = [ + * 'grpc' => [...], + * 'rest' => [...], + * ]; + * See the {@see \Google\ApiCore\Transport\GrpcTransport::build()} and + * {@see \Google\ApiCore\Transport\RestTransport::build()} methods for the + * supported options. + * @type callable $clientCertSource + * A callable which returns the client cert as a string. This can be used to + * provide a certificate and private key to the transport layer for mTLS. + * } + * + * @throws ValidationException + */ + public function __construct(array $options = []) + { + $clientOptions = $this->buildClientOptions($options); + $this->setClientOptions($clientOptions); + $this->operationsClient = $this->createOperationsClient($clientOptions); + } + + /** Handles execution of the async variants for each documented method. */ + public function __call($method, $args) + { + if (substr($method, -5) !== 'Async') { + trigger_error('Call to undefined method ' . __CLASS__ . "::$method()", E_USER_ERROR); + } + + array_unshift($args, substr($method, 0, -5)); + return call_user_func_array([$this, 'startAsyncCall'], $args); + } + + /** + * Detach LUN from Instance. + * + * The async variant is {@see self::detachLunAsync()} . + * + * @param DetachLunRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function detachLun(DetachLunRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('DetachLun', $request, $callOptions)->wait(); + } + + /** + * Get details about a single server. + * + * The async variant is {@see self::getInstanceAsync()} . + * + * @param GetInstanceRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Instance + * + * @throws ApiException Thrown if the API call fails. + */ + public function getInstance(GetInstanceRequest $request, array $callOptions = []): Instance + { + return $this->startApiCall('GetInstance', $request, $callOptions)->wait(); + } + + /** + * Get details of a single storage logical unit number(LUN). + * + * The async variant is {@see self::getLunAsync()} . + * + * @param GetLunRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Lun + * + * @throws ApiException Thrown if the API call fails. + */ + public function getLun(GetLunRequest $request, array $callOptions = []): Lun + { + return $this->startApiCall('GetLun', $request, $callOptions)->wait(); + } + + /** + * Get details of a single network. + * + * The async variant is {@see self::getNetworkAsync()} . + * + * @param GetNetworkRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Network + * + * @throws ApiException Thrown if the API call fails. + */ + public function getNetwork(GetNetworkRequest $request, array $callOptions = []): Network + { + return $this->startApiCall('GetNetwork', $request, $callOptions)->wait(); + } + + /** + * Get details of a single NFS share. + * + * The async variant is {@see self::getNfsShareAsync()} . + * + * @param GetNfsShareRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return NfsShare + * + * @throws ApiException Thrown if the API call fails. + */ + public function getNfsShare(GetNfsShareRequest $request, array $callOptions = []): NfsShare + { + return $this->startApiCall('GetNfsShare', $request, $callOptions)->wait(); + } + + /** + * Get details of a single storage volume. + * + * The async variant is {@see self::getVolumeAsync()} . + * + * @param GetVolumeRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Volume + * + * @throws ApiException Thrown if the API call fails. + */ + public function getVolume(GetVolumeRequest $request, array $callOptions = []): Volume + { + return $this->startApiCall('GetVolume', $request, $callOptions)->wait(); + } + + /** + * List servers in a given project and location. + * + * The async variant is {@see self::listInstancesAsync()} . + * + * @param ListInstancesRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listInstances(ListInstancesRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListInstances', $request, $callOptions); + } + + /** + * List storage volume luns for given storage volume. + * + * The async variant is {@see self::listLunsAsync()} . + * + * @param ListLunsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listLuns(ListLunsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListLuns', $request, $callOptions); + } + + /** + * List all Networks (and used IPs for each Network) in the vendor account + * associated with the specified project. + * + * The async variant is {@see self::listNetworkUsageAsync()} . + * + * @param ListNetworkUsageRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return ListNetworkUsageResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listNetworkUsage(ListNetworkUsageRequest $request, array $callOptions = []): ListNetworkUsageResponse + { + return $this->startApiCall('ListNetworkUsage', $request, $callOptions)->wait(); + } + + /** + * List network in a given project and location. + * + * The async variant is {@see self::listNetworksAsync()} . + * + * @param ListNetworksRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listNetworks(ListNetworksRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListNetworks', $request, $callOptions); + } + + /** + * List NFS shares. + * + * The async variant is {@see self::listNfsSharesAsync()} . + * + * @param ListNfsSharesRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listNfsShares(ListNfsSharesRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListNfsShares', $request, $callOptions); + } + + /** + * List storage volumes in a given project and location. + * + * The async variant is {@see self::listVolumesAsync()} . + * + * @param ListVolumesRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listVolumes(ListVolumesRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListVolumes', $request, $callOptions); + } + + /** + * Perform an ungraceful, hard reset on a server. Equivalent to shutting the + * power off and then turning it back on. + * + * The async variant is {@see self::resetInstanceAsync()} . + * + * @param ResetInstanceRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function resetInstance(ResetInstanceRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('ResetInstance', $request, $callOptions)->wait(); + } + + /** + * Emergency Volume resize. + * + * The async variant is {@see self::resizeVolumeAsync()} . + * + * @param ResizeVolumeRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function resizeVolume(ResizeVolumeRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('ResizeVolume', $request, $callOptions)->wait(); + } + + /** + * Starts a server that was shutdown. + * + * The async variant is {@see self::startInstanceAsync()} . + * + * @param StartInstanceRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function startInstance(StartInstanceRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('StartInstance', $request, $callOptions)->wait(); + } + + /** + * Stop a running server. + * + * The async variant is {@see self::stopInstanceAsync()} . + * + * @param StopInstanceRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function stopInstance(StopInstanceRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('StopInstance', $request, $callOptions)->wait(); + } + + /** + * Update details of a single server. + * + * The async variant is {@see self::updateInstanceAsync()} . + * + * @param UpdateInstanceRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function updateInstance(UpdateInstanceRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('UpdateInstance', $request, $callOptions)->wait(); + } + + /** + * Update details of a single network. + * + * The async variant is {@see self::updateNetworkAsync()} . + * + * @param UpdateNetworkRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function updateNetwork(UpdateNetworkRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('UpdateNetwork', $request, $callOptions)->wait(); + } + + /** + * Update details of a single NFS share. + * + * The async variant is {@see self::updateNfsShareAsync()} . + * + * @param UpdateNfsShareRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function updateNfsShare(UpdateNfsShareRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('UpdateNfsShare', $request, $callOptions)->wait(); + } + + /** + * Update details of a single storage volume. + * + * The async variant is {@see self::updateVolumeAsync()} . + * + * @param UpdateVolumeRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function updateVolume(UpdateVolumeRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('UpdateVolume', $request, $callOptions)->wait(); + } +} diff --git a/BareMetalSolution/src/V2/DetachLunRequest.php b/BareMetalSolution/src/V2/DetachLunRequest.php index 1396be0bb106..ea2e1665087a 100644 --- a/BareMetalSolution/src/V2/DetachLunRequest.php +++ b/BareMetalSolution/src/V2/DetachLunRequest.php @@ -28,6 +28,23 @@ class DetachLunRequest extends \Google\Protobuf\Internal\Message */ private $lun = ''; + /** + * @param string $instance Required. Name of the instance. Please see + * {@see BareMetalSolutionClient::instanceName()} for help formatting this field. + * @param string $lun Required. Name of the Lun to detach. Please see + * {@see BareMetalSolutionClient::lunName()} for help formatting this field. + * + * @return \Google\Cloud\BareMetalSolution\V2\DetachLunRequest + * + * @experimental + */ + public static function build(string $instance, string $lun): self + { + return (new self()) + ->setInstance($instance) + ->setLun($lun); + } + /** * Constructor. * diff --git a/BareMetalSolution/src/V2/GetInstanceRequest.php b/BareMetalSolution/src/V2/GetInstanceRequest.php index 3dbd85c7a179..d7e28a3e1c91 100644 --- a/BareMetalSolution/src/V2/GetInstanceRequest.php +++ b/BareMetalSolution/src/V2/GetInstanceRequest.php @@ -22,6 +22,20 @@ class GetInstanceRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. Name of the resource. Please see + * {@see BareMetalSolutionClient::instanceName()} for help formatting this field. + * + * @return \Google\Cloud\BareMetalSolution\V2\GetInstanceRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/BareMetalSolution/src/V2/GetLunRequest.php b/BareMetalSolution/src/V2/GetLunRequest.php index a51e11a56539..0a050a1b3825 100644 --- a/BareMetalSolution/src/V2/GetLunRequest.php +++ b/BareMetalSolution/src/V2/GetLunRequest.php @@ -22,6 +22,20 @@ class GetLunRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. Name of the resource. Please see + * {@see BareMetalSolutionClient::lunName()} for help formatting this field. + * + * @return \Google\Cloud\BareMetalSolution\V2\GetLunRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/BareMetalSolution/src/V2/GetNetworkRequest.php b/BareMetalSolution/src/V2/GetNetworkRequest.php index 03373aad9acd..f1ab274ee7b3 100644 --- a/BareMetalSolution/src/V2/GetNetworkRequest.php +++ b/BareMetalSolution/src/V2/GetNetworkRequest.php @@ -22,6 +22,20 @@ class GetNetworkRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. Name of the resource. Please see + * {@see BareMetalSolutionClient::networkName()} for help formatting this field. + * + * @return \Google\Cloud\BareMetalSolution\V2\GetNetworkRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/BareMetalSolution/src/V2/GetNfsShareRequest.php b/BareMetalSolution/src/V2/GetNfsShareRequest.php index f44f00459a4a..7699023eb890 100644 --- a/BareMetalSolution/src/V2/GetNfsShareRequest.php +++ b/BareMetalSolution/src/V2/GetNfsShareRequest.php @@ -22,6 +22,20 @@ class GetNfsShareRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. Name of the resource. Please see + * {@see BareMetalSolutionClient::nFSShareName()} for help formatting this field. + * + * @return \Google\Cloud\BareMetalSolution\V2\GetNfsShareRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/BareMetalSolution/src/V2/GetVolumeRequest.php b/BareMetalSolution/src/V2/GetVolumeRequest.php index dce61ec5ad8a..50e02fdc1e89 100644 --- a/BareMetalSolution/src/V2/GetVolumeRequest.php +++ b/BareMetalSolution/src/V2/GetVolumeRequest.php @@ -22,6 +22,20 @@ class GetVolumeRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. Name of the resource. Please see + * {@see BareMetalSolutionClient::volumeName()} for help formatting this field. + * + * @return \Google\Cloud\BareMetalSolution\V2\GetVolumeRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/BareMetalSolution/src/V2/ListInstancesRequest.php b/BareMetalSolution/src/V2/ListInstancesRequest.php index 47e2f3c3a2c7..316a7a6ebd7b 100644 --- a/BareMetalSolution/src/V2/ListInstancesRequest.php +++ b/BareMetalSolution/src/V2/ListInstancesRequest.php @@ -41,6 +41,20 @@ class ListInstancesRequest extends \Google\Protobuf\Internal\Message */ private $filter = ''; + /** + * @param string $parent Required. Parent value for ListInstancesRequest. Please see + * {@see BareMetalSolutionClient::locationName()} for help formatting this field. + * + * @return \Google\Cloud\BareMetalSolution\V2\ListInstancesRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/BareMetalSolution/src/V2/ListLunsRequest.php b/BareMetalSolution/src/V2/ListLunsRequest.php index 19536bd8dacf..ed41afcbe5ec 100644 --- a/BareMetalSolution/src/V2/ListLunsRequest.php +++ b/BareMetalSolution/src/V2/ListLunsRequest.php @@ -35,6 +35,20 @@ class ListLunsRequest extends \Google\Protobuf\Internal\Message */ private $page_token = ''; + /** + * @param string $parent Required. Parent value for ListLunsRequest. Please see + * {@see BareMetalSolutionClient::volumeName()} for help formatting this field. + * + * @return \Google\Cloud\BareMetalSolution\V2\ListLunsRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/BareMetalSolution/src/V2/ListNetworkUsageRequest.php b/BareMetalSolution/src/V2/ListNetworkUsageRequest.php index 8960cd3a0ae0..d74b673fd85a 100644 --- a/BareMetalSolution/src/V2/ListNetworkUsageRequest.php +++ b/BareMetalSolution/src/V2/ListNetworkUsageRequest.php @@ -22,6 +22,20 @@ class ListNetworkUsageRequest extends \Google\Protobuf\Internal\Message */ private $location = ''; + /** + * @param string $location Required. Parent value (project and location). Please see + * {@see BareMetalSolutionClient::locationName()} for help formatting this field. + * + * @return \Google\Cloud\BareMetalSolution\V2\ListNetworkUsageRequest + * + * @experimental + */ + public static function build(string $location): self + { + return (new self()) + ->setLocation($location); + } + /** * Constructor. * diff --git a/BareMetalSolution/src/V2/ListNetworksRequest.php b/BareMetalSolution/src/V2/ListNetworksRequest.php index e2eb42262ab6..2e78fca0aff7 100644 --- a/BareMetalSolution/src/V2/ListNetworksRequest.php +++ b/BareMetalSolution/src/V2/ListNetworksRequest.php @@ -41,6 +41,20 @@ class ListNetworksRequest extends \Google\Protobuf\Internal\Message */ private $filter = ''; + /** + * @param string $parent Required. Parent value for ListNetworksRequest. Please see + * {@see BareMetalSolutionClient::locationName()} for help formatting this field. + * + * @return \Google\Cloud\BareMetalSolution\V2\ListNetworksRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/BareMetalSolution/src/V2/ListNfsSharesRequest.php b/BareMetalSolution/src/V2/ListNfsSharesRequest.php index 11b01340a77a..0c079132692a 100644 --- a/BareMetalSolution/src/V2/ListNfsSharesRequest.php +++ b/BareMetalSolution/src/V2/ListNfsSharesRequest.php @@ -41,6 +41,20 @@ class ListNfsSharesRequest extends \Google\Protobuf\Internal\Message */ private $filter = ''; + /** + * @param string $parent Required. Parent value for ListNfsSharesRequest. Please see + * {@see BareMetalSolutionClient::locationName()} for help formatting this field. + * + * @return \Google\Cloud\BareMetalSolution\V2\ListNfsSharesRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/BareMetalSolution/src/V2/ListVolumesRequest.php b/BareMetalSolution/src/V2/ListVolumesRequest.php index 1d11bac9d6a2..c253e4ea61bd 100644 --- a/BareMetalSolution/src/V2/ListVolumesRequest.php +++ b/BareMetalSolution/src/V2/ListVolumesRequest.php @@ -41,6 +41,20 @@ class ListVolumesRequest extends \Google\Protobuf\Internal\Message */ private $filter = ''; + /** + * @param string $parent Required. Parent value for ListVolumesRequest. Please see + * {@see BareMetalSolutionClient::locationName()} for help formatting this field. + * + * @return \Google\Cloud\BareMetalSolution\V2\ListVolumesRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/BareMetalSolution/src/V2/ResetInstanceRequest.php b/BareMetalSolution/src/V2/ResetInstanceRequest.php index 099819a2ec7b..f9f90000b755 100644 --- a/BareMetalSolution/src/V2/ResetInstanceRequest.php +++ b/BareMetalSolution/src/V2/ResetInstanceRequest.php @@ -22,6 +22,20 @@ class ResetInstanceRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. Name of the resource. Please see + * {@see BareMetalSolutionClient::instanceName()} for help formatting this field. + * + * @return \Google\Cloud\BareMetalSolution\V2\ResetInstanceRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/BareMetalSolution/src/V2/ResizeVolumeRequest.php b/BareMetalSolution/src/V2/ResizeVolumeRequest.php index df8b77f75bd3..46fe33196be2 100644 --- a/BareMetalSolution/src/V2/ResizeVolumeRequest.php +++ b/BareMetalSolution/src/V2/ResizeVolumeRequest.php @@ -28,6 +28,22 @@ class ResizeVolumeRequest extends \Google\Protobuf\Internal\Message */ private $size_gib = 0; + /** + * @param string $volume Required. Volume to resize. Please see + * {@see BareMetalSolutionClient::volumeName()} for help formatting this field. + * @param int $sizeGib New Volume size, in GiB. + * + * @return \Google\Cloud\BareMetalSolution\V2\ResizeVolumeRequest + * + * @experimental + */ + public static function build(string $volume, int $sizeGib): self + { + return (new self()) + ->setVolume($volume) + ->setSizeGib($sizeGib); + } + /** * Constructor. * diff --git a/BareMetalSolution/src/V2/StartInstanceRequest.php b/BareMetalSolution/src/V2/StartInstanceRequest.php index 8517abb3432a..ac899e87e1d8 100644 --- a/BareMetalSolution/src/V2/StartInstanceRequest.php +++ b/BareMetalSolution/src/V2/StartInstanceRequest.php @@ -22,6 +22,20 @@ class StartInstanceRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. Name of the resource. Please see + * {@see BareMetalSolutionClient::instanceName()} for help formatting this field. + * + * @return \Google\Cloud\BareMetalSolution\V2\StartInstanceRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/BareMetalSolution/src/V2/StopInstanceRequest.php b/BareMetalSolution/src/V2/StopInstanceRequest.php index 5b499d0c58a0..93a98e71ac40 100644 --- a/BareMetalSolution/src/V2/StopInstanceRequest.php +++ b/BareMetalSolution/src/V2/StopInstanceRequest.php @@ -22,6 +22,20 @@ class StopInstanceRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. Name of the resource. Please see + * {@see BareMetalSolutionClient::instanceName()} for help formatting this field. + * + * @return \Google\Cloud\BareMetalSolution\V2\StopInstanceRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/BareMetalSolution/src/V2/UpdateInstanceRequest.php b/BareMetalSolution/src/V2/UpdateInstanceRequest.php index 80f499e2fa88..678f9a38bd86 100644 --- a/BareMetalSolution/src/V2/UpdateInstanceRequest.php +++ b/BareMetalSolution/src/V2/UpdateInstanceRequest.php @@ -34,6 +34,28 @@ class UpdateInstanceRequest extends \Google\Protobuf\Internal\Message */ private $update_mask = null; + /** + * @param \Google\Cloud\BareMetalSolution\V2\Instance $instance Required. The server to update. + * + * The `name` field is used to identify the instance to update. + * Format: projects/{project}/locations/{location}/instances/{instance} + * @param \Google\Protobuf\FieldMask $updateMask The list of fields to update. + * The currently supported fields are: + * `labels` + * `hyperthreading_enabled` + * `os_image` + * + * @return \Google\Cloud\BareMetalSolution\V2\UpdateInstanceRequest + * + * @experimental + */ + public static function build(\Google\Cloud\BareMetalSolution\V2\Instance $instance, \Google\Protobuf\FieldMask $updateMask): self + { + return (new self()) + ->setInstance($instance) + ->setUpdateMask($updateMask); + } + /** * Constructor. * diff --git a/BareMetalSolution/src/V2/UpdateNetworkRequest.php b/BareMetalSolution/src/V2/UpdateNetworkRequest.php index 36996aef2ef5..729e43d1a456 100644 --- a/BareMetalSolution/src/V2/UpdateNetworkRequest.php +++ b/BareMetalSolution/src/V2/UpdateNetworkRequest.php @@ -32,6 +32,26 @@ class UpdateNetworkRequest extends \Google\Protobuf\Internal\Message */ private $update_mask = null; + /** + * @param \Google\Cloud\BareMetalSolution\V2\Network $network Required. The network to update. + * + * The `name` field is used to identify the instance to update. + * Format: projects/{project}/locations/{location}/networks/{network} + * @param \Google\Protobuf\FieldMask $updateMask The list of fields to update. + * The only currently supported fields are: + * `labels`, `reservations` + * + * @return \Google\Cloud\BareMetalSolution\V2\UpdateNetworkRequest + * + * @experimental + */ + public static function build(\Google\Cloud\BareMetalSolution\V2\Network $network, \Google\Protobuf\FieldMask $updateMask): self + { + return (new self()) + ->setNetwork($network) + ->setUpdateMask($updateMask); + } + /** * Constructor. * diff --git a/BareMetalSolution/src/V2/UpdateNfsShareRequest.php b/BareMetalSolution/src/V2/UpdateNfsShareRequest.php index 2c760d8ea88b..73c61698b019 100644 --- a/BareMetalSolution/src/V2/UpdateNfsShareRequest.php +++ b/BareMetalSolution/src/V2/UpdateNfsShareRequest.php @@ -32,6 +32,26 @@ class UpdateNfsShareRequest extends \Google\Protobuf\Internal\Message */ private $update_mask = null; + /** + * @param \Google\Cloud\BareMetalSolution\V2\NfsShare $nfsShare Required. The NFS share to update. + * + * The `name` field is used to identify the NFS share to update. + * Format: projects/{project}/locations/{location}/nfsShares/{nfs_share} + * @param \Google\Protobuf\FieldMask $updateMask The list of fields to update. + * The only currently supported fields are: + * `labels` + * + * @return \Google\Cloud\BareMetalSolution\V2\UpdateNfsShareRequest + * + * @experimental + */ + public static function build(\Google\Cloud\BareMetalSolution\V2\NfsShare $nfsShare, \Google\Protobuf\FieldMask $updateMask): self + { + return (new self()) + ->setNfsShare($nfsShare) + ->setUpdateMask($updateMask); + } + /** * Constructor. * diff --git a/BareMetalSolution/src/V2/UpdateVolumeRequest.php b/BareMetalSolution/src/V2/UpdateVolumeRequest.php index be5ca4b0f422..149f0ecdbe27 100644 --- a/BareMetalSolution/src/V2/UpdateVolumeRequest.php +++ b/BareMetalSolution/src/V2/UpdateVolumeRequest.php @@ -36,6 +36,30 @@ class UpdateVolumeRequest extends \Google\Protobuf\Internal\Message */ private $update_mask = null; + /** + * @param \Google\Cloud\BareMetalSolution\V2\Volume $volume Required. The volume to update. + * + * The `name` field is used to identify the volume to update. + * Format: projects/{project}/locations/{location}/volumes/{volume} + * @param \Google\Protobuf\FieldMask $updateMask The list of fields to update. + * The only currently supported fields are: + * `snapshot_auto_delete_behavior` + * `snapshot_schedule_policy_name` + * 'labels' + * 'snapshot_enabled' + * 'snapshot_reservation_detail.reserved_space_percent' + * + * @return \Google\Cloud\BareMetalSolution\V2\UpdateVolumeRequest + * + * @experimental + */ + public static function build(\Google\Cloud\BareMetalSolution\V2\Volume $volume, \Google\Protobuf\FieldMask $updateMask): self + { + return (new self()) + ->setVolume($volume) + ->setUpdateMask($updateMask); + } + /** * Constructor. * diff --git a/BareMetalSolution/src/V2/resources/bare_metal_solution_descriptor_config.php b/BareMetalSolution/src/V2/resources/bare_metal_solution_descriptor_config.php index 0ba834ac2936..ba98f4d93a1d 100644 --- a/BareMetalSolution/src/V2/resources/bare_metal_solution_descriptor_config.php +++ b/BareMetalSolution/src/V2/resources/bare_metal_solution_descriptor_config.php @@ -12,6 +12,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'instance', + 'fieldAccessors' => [ + 'getInstance', + ], + ], + ], ], 'ResetInstance' => [ 'longRunning' => [ @@ -22,6 +31,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'ResizeVolume' => [ 'longRunning' => [ @@ -32,6 +50,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'volume', + 'fieldAccessors' => [ + 'getVolume', + ], + ], + ], ], 'StartInstance' => [ 'longRunning' => [ @@ -42,6 +69,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'StopInstance' => [ 'longRunning' => [ @@ -52,6 +88,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'UpdateInstance' => [ 'longRunning' => [ @@ -62,6 +107,16 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'instance.name', + 'fieldAccessors' => [ + 'getInstance', + 'getName', + ], + ], + ], ], 'UpdateNetwork' => [ 'longRunning' => [ @@ -72,6 +127,16 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'network.name', + 'fieldAccessors' => [ + 'getNetwork', + 'getName', + ], + ], + ], ], 'UpdateNfsShare' => [ 'longRunning' => [ @@ -82,6 +147,16 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'nfs_share.name', + 'fieldAccessors' => [ + 'getNfsShare', + 'getName', + ], + ], + ], ], 'UpdateVolume' => [ 'longRunning' => [ @@ -92,6 +167,76 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'volume.name', + 'fieldAccessors' => [ + 'getVolume', + 'getName', + ], + ], + ], + ], + 'GetInstance' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\BareMetalSolution\V2\Instance', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetLun' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\BareMetalSolution\V2\Lun', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetNetwork' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\BareMetalSolution\V2\Network', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetNfsShare' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\BareMetalSolution\V2\NfsShare', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetVolume' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\BareMetalSolution\V2\Volume', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'ListInstances' => [ 'pageStreaming' => [ @@ -102,6 +247,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getInstances', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\BareMetalSolution\V2\ListInstancesResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ListLuns' => [ 'pageStreaming' => [ @@ -112,6 +267,28 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getLuns', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\BareMetalSolution\V2\ListLunsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'ListNetworkUsage' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\BareMetalSolution\V2\ListNetworkUsageResponse', + 'headerParams' => [ + [ + 'keyName' => 'location', + 'fieldAccessors' => [ + 'getLocation', + ], + ], + ], ], 'ListNetworks' => [ 'pageStreaming' => [ @@ -122,6 +299,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getNetworks', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\BareMetalSolution\V2\ListNetworksResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ListNfsShares' => [ 'pageStreaming' => [ @@ -132,6 +319,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getNfsShares', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\BareMetalSolution\V2\ListNfsSharesResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ListVolumes' => [ 'pageStreaming' => [ @@ -142,6 +339,25 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getVolumes', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\BareMetalSolution\V2\ListVolumesResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'templateMap' => [ + 'instance' => 'projects/{project}/locations/{location}/instances/{instance}', + 'location' => 'projects/{project}/locations/{location}', + 'lun' => 'projects/{project}/locations/{location}/volumes/{volume}/luns/{lun}', + 'nFSShare' => 'projects/{project}/locations/{location}/nfsShares/{nfs_share}', + 'network' => 'projects/{project}/locations/{location}/networks/{network}', + 'serverNetworkTemplate' => 'projects/{project}/locations/{location}/serverNetworkTemplate/{server_network_template}', + 'volume' => 'projects/{project}/locations/{location}/volumes/{volume}', ], ], ], diff --git a/BareMetalSolution/tests/Unit/V2/Client/BareMetalSolutionClientTest.php b/BareMetalSolution/tests/Unit/V2/Client/BareMetalSolutionClientTest.php new file mode 100644 index 000000000000..b4b990fe6a5d --- /dev/null +++ b/BareMetalSolution/tests/Unit/V2/Client/BareMetalSolutionClientTest.php @@ -0,0 +1,2161 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return BareMetalSolutionClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new BareMetalSolutionClient($options); + } + + /** @test */ + public function detachLunTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/detachLunTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $id = 'id3355'; + $machineType = 'machineType1838323762'; + $hyperthreadingEnabled = true; + $interactiveSerialConsoleEnabled = false; + $osImage = 'osImage1982209856'; + $pod = 'pod111173'; + $networkTemplate = 'networkTemplate215365483'; + $expectedResponse = new Instance(); + $expectedResponse->setName($name); + $expectedResponse->setId($id); + $expectedResponse->setMachineType($machineType); + $expectedResponse->setHyperthreadingEnabled($hyperthreadingEnabled); + $expectedResponse->setInteractiveSerialConsoleEnabled($interactiveSerialConsoleEnabled); + $expectedResponse->setOsImage($osImage); + $expectedResponse->setPod($pod); + $expectedResponse->setNetworkTemplate($networkTemplate); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/detachLunTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedInstance = $gapicClient->instanceName('[PROJECT]', '[LOCATION]', '[INSTANCE]'); + $formattedLun = $gapicClient->lunName('[PROJECT]', '[LOCATION]', '[VOLUME]', '[LUN]'); + $request = (new DetachLunRequest()) + ->setInstance($formattedInstance) + ->setLun($formattedLun); + $response = $gapicClient->detachLun($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.baremetalsolution.v2.BareMetalSolution/DetachLun', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getInstance(); + $this->assertProtobufEquals($formattedInstance, $actualValue); + $actualValue = $actualApiRequestObject->getLun(); + $this->assertProtobufEquals($formattedLun, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/detachLunTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function detachLunExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/detachLunTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedInstance = $gapicClient->instanceName('[PROJECT]', '[LOCATION]', '[INSTANCE]'); + $formattedLun = $gapicClient->lunName('[PROJECT]', '[LOCATION]', '[VOLUME]', '[LUN]'); + $request = (new DetachLunRequest()) + ->setInstance($formattedInstance) + ->setLun($formattedLun); + $response = $gapicClient->detachLun($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/detachLunTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function getInstanceTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $id = 'id3355'; + $machineType = 'machineType1838323762'; + $hyperthreadingEnabled = true; + $interactiveSerialConsoleEnabled = false; + $osImage = 'osImage1982209856'; + $pod = 'pod111173'; + $networkTemplate = 'networkTemplate215365483'; + $expectedResponse = new Instance(); + $expectedResponse->setName($name2); + $expectedResponse->setId($id); + $expectedResponse->setMachineType($machineType); + $expectedResponse->setHyperthreadingEnabled($hyperthreadingEnabled); + $expectedResponse->setInteractiveSerialConsoleEnabled($interactiveSerialConsoleEnabled); + $expectedResponse->setOsImage($osImage); + $expectedResponse->setPod($pod); + $expectedResponse->setNetworkTemplate($networkTemplate); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->instanceName('[PROJECT]', '[LOCATION]', '[INSTANCE]'); + $request = (new GetInstanceRequest()) + ->setName($formattedName); + $response = $gapicClient->getInstance($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.baremetalsolution.v2.BareMetalSolution/GetInstance', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getInstanceExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->instanceName('[PROJECT]', '[LOCATION]', '[INSTANCE]'); + $request = (new GetInstanceRequest()) + ->setName($formattedName); + try { + $gapicClient->getInstance($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getLunTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $id = 'id3355'; + $sizeGb = 2105542105; + $storageVolume = 'storageVolume-768806562'; + $shareable = false; + $bootLun = true; + $wwid = 'wwid3662843'; + $expectedResponse = new Lun(); + $expectedResponse->setName($name2); + $expectedResponse->setId($id); + $expectedResponse->setSizeGb($sizeGb); + $expectedResponse->setStorageVolume($storageVolume); + $expectedResponse->setShareable($shareable); + $expectedResponse->setBootLun($bootLun); + $expectedResponse->setWwid($wwid); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->lunName('[PROJECT]', '[LOCATION]', '[VOLUME]', '[LUN]'); + $request = (new GetLunRequest()) + ->setName($formattedName); + $response = $gapicClient->getLun($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.baremetalsolution.v2.BareMetalSolution/GetLun', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getLunExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->lunName('[PROJECT]', '[LOCATION]', '[VOLUME]', '[LUN]'); + $request = (new GetLunRequest()) + ->setName($formattedName); + try { + $gapicClient->getLun($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getNetworkTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $id = 'id3355'; + $ipAddress = 'ipAddress1480014044'; + $vlanId = 'vlanId536153463'; + $cidr = 'cidr3053428'; + $servicesCidr = 'servicesCidr-1169831243'; + $expectedResponse = new Network(); + $expectedResponse->setName($name2); + $expectedResponse->setId($id); + $expectedResponse->setIpAddress($ipAddress); + $expectedResponse->setVlanId($vlanId); + $expectedResponse->setCidr($cidr); + $expectedResponse->setServicesCidr($servicesCidr); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->networkName('[PROJECT]', '[LOCATION]', '[NETWORK]'); + $request = (new GetNetworkRequest()) + ->setName($formattedName); + $response = $gapicClient->getNetwork($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.baremetalsolution.v2.BareMetalSolution/GetNetwork', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getNetworkExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->networkName('[PROJECT]', '[LOCATION]', '[NETWORK]'); + $request = (new GetNetworkRequest()) + ->setName($formattedName); + try { + $gapicClient->getNetwork($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getNfsShareTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $nfsShareId = 'nfsShareId931294079'; + $volume = 'volume-810883302'; + $expectedResponse = new NfsShare(); + $expectedResponse->setName($name2); + $expectedResponse->setNfsShareId($nfsShareId); + $expectedResponse->setVolume($volume); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->nFSShareName('[PROJECT]', '[LOCATION]', '[NFS_SHARE]'); + $request = (new GetNfsShareRequest()) + ->setName($formattedName); + $response = $gapicClient->getNfsShare($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.baremetalsolution.v2.BareMetalSolution/GetNfsShare', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getNfsShareExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->nFSShareName('[PROJECT]', '[LOCATION]', '[NFS_SHARE]'); + $request = (new GetNfsShareRequest()) + ->setName($formattedName); + try { + $gapicClient->getNfsShare($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getVolumeTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $id = 'id3355'; + $requestedSizeGib = 525454387; + $currentSizeGib = 72696456; + $emergencySizeGib = 1936971120; + $autoGrownSizeGib = 1245638678; + $remainingSpaceGib = 1423108606; + $snapshotEnabled = true; + $pod = 'pod111173'; + $expectedResponse = new Volume(); + $expectedResponse->setName($name2); + $expectedResponse->setId($id); + $expectedResponse->setRequestedSizeGib($requestedSizeGib); + $expectedResponse->setCurrentSizeGib($currentSizeGib); + $expectedResponse->setEmergencySizeGib($emergencySizeGib); + $expectedResponse->setAutoGrownSizeGib($autoGrownSizeGib); + $expectedResponse->setRemainingSpaceGib($remainingSpaceGib); + $expectedResponse->setSnapshotEnabled($snapshotEnabled); + $expectedResponse->setPod($pod); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->volumeName('[PROJECT]', '[LOCATION]', '[VOLUME]'); + $request = (new GetVolumeRequest()) + ->setName($formattedName); + $response = $gapicClient->getVolume($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.baremetalsolution.v2.BareMetalSolution/GetVolume', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getVolumeExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->volumeName('[PROJECT]', '[LOCATION]', '[VOLUME]'); + $request = (new GetVolumeRequest()) + ->setName($formattedName); + try { + $gapicClient->getVolume($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listInstancesTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $instancesElement = new Instance(); + $instances = [ + $instancesElement, + ]; + $expectedResponse = new ListInstancesResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setInstances($instances); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListInstancesRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listInstances($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getInstances()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.baremetalsolution.v2.BareMetalSolution/ListInstances', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listInstancesExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListInstancesRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listInstances($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listLunsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $lunsElement = new Lun(); + $luns = [ + $lunsElement, + ]; + $expectedResponse = new ListLunsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setLuns($luns); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->volumeName('[PROJECT]', '[LOCATION]', '[VOLUME]'); + $request = (new ListLunsRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listLuns($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getLuns()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.baremetalsolution.v2.BareMetalSolution/ListLuns', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listLunsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->volumeName('[PROJECT]', '[LOCATION]', '[VOLUME]'); + $request = (new ListLunsRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listLuns($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listNetworkUsageTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new ListNetworkUsageResponse(); + $transport->addResponse($expectedResponse); + // Mock request + $formattedLocation = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListNetworkUsageRequest()) + ->setLocation($formattedLocation); + $response = $gapicClient->listNetworkUsage($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.baremetalsolution.v2.BareMetalSolution/ListNetworkUsage', $actualFuncCall); + $actualValue = $actualRequestObject->getLocation(); + $this->assertProtobufEquals($formattedLocation, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listNetworkUsageExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedLocation = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListNetworkUsageRequest()) + ->setLocation($formattedLocation); + try { + $gapicClient->listNetworkUsage($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listNetworksTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $networksElement = new Network(); + $networks = [ + $networksElement, + ]; + $expectedResponse = new ListNetworksResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setNetworks($networks); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListNetworksRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listNetworks($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getNetworks()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.baremetalsolution.v2.BareMetalSolution/ListNetworks', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listNetworksExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListNetworksRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listNetworks($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listNfsSharesTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $nfsSharesElement = new NfsShare(); + $nfsShares = [ + $nfsSharesElement, + ]; + $expectedResponse = new ListNfsSharesResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setNfsShares($nfsShares); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListNfsSharesRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listNfsShares($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getNfsShares()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.baremetalsolution.v2.BareMetalSolution/ListNfsShares', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listNfsSharesExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListNfsSharesRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listNfsShares($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listVolumesTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $volumesElement = new Volume(); + $volumes = [ + $volumesElement, + ]; + $expectedResponse = new ListVolumesResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setVolumes($volumes); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListVolumesRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listVolumes($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getVolumes()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.baremetalsolution.v2.BareMetalSolution/ListVolumes', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listVolumesExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListVolumesRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listVolumes($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function resetInstanceTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/resetInstanceTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new ResetInstanceResponse(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/resetInstanceTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->instanceName('[PROJECT]', '[LOCATION]', '[INSTANCE]'); + $request = (new ResetInstanceRequest()) + ->setName($formattedName); + $response = $gapicClient->resetInstance($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.baremetalsolution.v2.BareMetalSolution/ResetInstance', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/resetInstanceTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function resetInstanceExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/resetInstanceTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->instanceName('[PROJECT]', '[LOCATION]', '[INSTANCE]'); + $request = (new ResetInstanceRequest()) + ->setName($formattedName); + $response = $gapicClient->resetInstance($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/resetInstanceTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function resizeVolumeTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/resizeVolumeTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $id = 'id3355'; + $requestedSizeGib = 525454387; + $currentSizeGib = 72696456; + $emergencySizeGib = 1936971120; + $autoGrownSizeGib = 1245638678; + $remainingSpaceGib = 1423108606; + $snapshotEnabled = true; + $pod = 'pod111173'; + $expectedResponse = new Volume(); + $expectedResponse->setName($name); + $expectedResponse->setId($id); + $expectedResponse->setRequestedSizeGib($requestedSizeGib); + $expectedResponse->setCurrentSizeGib($currentSizeGib); + $expectedResponse->setEmergencySizeGib($emergencySizeGib); + $expectedResponse->setAutoGrownSizeGib($autoGrownSizeGib); + $expectedResponse->setRemainingSpaceGib($remainingSpaceGib); + $expectedResponse->setSnapshotEnabled($snapshotEnabled); + $expectedResponse->setPod($pod); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/resizeVolumeTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedVolume = $gapicClient->volumeName('[PROJECT]', '[LOCATION]', '[VOLUME]'); + $request = (new ResizeVolumeRequest()) + ->setVolume($formattedVolume); + $response = $gapicClient->resizeVolume($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.baremetalsolution.v2.BareMetalSolution/ResizeVolume', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getVolume(); + $this->assertProtobufEquals($formattedVolume, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/resizeVolumeTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function resizeVolumeExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/resizeVolumeTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedVolume = $gapicClient->volumeName('[PROJECT]', '[LOCATION]', '[VOLUME]'); + $request = (new ResizeVolumeRequest()) + ->setVolume($formattedVolume); + $response = $gapicClient->resizeVolume($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/resizeVolumeTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function startInstanceTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/startInstanceTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new StartInstanceResponse(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/startInstanceTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->instanceName('[PROJECT]', '[LOCATION]', '[INSTANCE]'); + $request = (new StartInstanceRequest()) + ->setName($formattedName); + $response = $gapicClient->startInstance($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.baremetalsolution.v2.BareMetalSolution/StartInstance', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/startInstanceTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function startInstanceExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/startInstanceTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->instanceName('[PROJECT]', '[LOCATION]', '[INSTANCE]'); + $request = (new StartInstanceRequest()) + ->setName($formattedName); + $response = $gapicClient->startInstance($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/startInstanceTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function stopInstanceTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/stopInstanceTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new StopInstanceResponse(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/stopInstanceTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->instanceName('[PROJECT]', '[LOCATION]', '[INSTANCE]'); + $request = (new StopInstanceRequest()) + ->setName($formattedName); + $response = $gapicClient->stopInstance($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.baremetalsolution.v2.BareMetalSolution/StopInstance', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/stopInstanceTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function stopInstanceExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/stopInstanceTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->instanceName('[PROJECT]', '[LOCATION]', '[INSTANCE]'); + $request = (new StopInstanceRequest()) + ->setName($formattedName); + $response = $gapicClient->stopInstance($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/stopInstanceTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function updateInstanceTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/updateInstanceTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $id = 'id3355'; + $machineType = 'machineType1838323762'; + $hyperthreadingEnabled = true; + $interactiveSerialConsoleEnabled = false; + $osImage = 'osImage1982209856'; + $pod = 'pod111173'; + $networkTemplate = 'networkTemplate215365483'; + $expectedResponse = new Instance(); + $expectedResponse->setName($name); + $expectedResponse->setId($id); + $expectedResponse->setMachineType($machineType); + $expectedResponse->setHyperthreadingEnabled($hyperthreadingEnabled); + $expectedResponse->setInteractiveSerialConsoleEnabled($interactiveSerialConsoleEnabled); + $expectedResponse->setOsImage($osImage); + $expectedResponse->setPod($pod); + $expectedResponse->setNetworkTemplate($networkTemplate); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/updateInstanceTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $instance = new Instance(); + $request = (new UpdateInstanceRequest()) + ->setInstance($instance); + $response = $gapicClient->updateInstance($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.baremetalsolution.v2.BareMetalSolution/UpdateInstance', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getInstance(); + $this->assertProtobufEquals($instance, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateInstanceTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function updateInstanceExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/updateInstanceTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $instance = new Instance(); + $request = (new UpdateInstanceRequest()) + ->setInstance($instance); + $response = $gapicClient->updateInstance($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateInstanceTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function updateNetworkTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/updateNetworkTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $id = 'id3355'; + $ipAddress = 'ipAddress1480014044'; + $vlanId = 'vlanId536153463'; + $cidr = 'cidr3053428'; + $servicesCidr = 'servicesCidr-1169831243'; + $expectedResponse = new Network(); + $expectedResponse->setName($name); + $expectedResponse->setId($id); + $expectedResponse->setIpAddress($ipAddress); + $expectedResponse->setVlanId($vlanId); + $expectedResponse->setCidr($cidr); + $expectedResponse->setServicesCidr($servicesCidr); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/updateNetworkTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $network = new Network(); + $request = (new UpdateNetworkRequest()) + ->setNetwork($network); + $response = $gapicClient->updateNetwork($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.baremetalsolution.v2.BareMetalSolution/UpdateNetwork', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getNetwork(); + $this->assertProtobufEquals($network, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateNetworkTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function updateNetworkExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/updateNetworkTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $network = new Network(); + $request = (new UpdateNetworkRequest()) + ->setNetwork($network); + $response = $gapicClient->updateNetwork($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateNetworkTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function updateNfsShareTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/updateNfsShareTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $nfsShareId = 'nfsShareId931294079'; + $volume = 'volume-810883302'; + $expectedResponse = new NfsShare(); + $expectedResponse->setName($name); + $expectedResponse->setNfsShareId($nfsShareId); + $expectedResponse->setVolume($volume); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/updateNfsShareTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $nfsShare = new NfsShare(); + $request = (new UpdateNfsShareRequest()) + ->setNfsShare($nfsShare); + $response = $gapicClient->updateNfsShare($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.baremetalsolution.v2.BareMetalSolution/UpdateNfsShare', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getNfsShare(); + $this->assertProtobufEquals($nfsShare, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateNfsShareTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function updateNfsShareExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/updateNfsShareTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $nfsShare = new NfsShare(); + $request = (new UpdateNfsShareRequest()) + ->setNfsShare($nfsShare); + $response = $gapicClient->updateNfsShare($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateNfsShareTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function updateVolumeTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/updateVolumeTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $id = 'id3355'; + $requestedSizeGib = 525454387; + $currentSizeGib = 72696456; + $emergencySizeGib = 1936971120; + $autoGrownSizeGib = 1245638678; + $remainingSpaceGib = 1423108606; + $snapshotEnabled = true; + $pod = 'pod111173'; + $expectedResponse = new Volume(); + $expectedResponse->setName($name); + $expectedResponse->setId($id); + $expectedResponse->setRequestedSizeGib($requestedSizeGib); + $expectedResponse->setCurrentSizeGib($currentSizeGib); + $expectedResponse->setEmergencySizeGib($emergencySizeGib); + $expectedResponse->setAutoGrownSizeGib($autoGrownSizeGib); + $expectedResponse->setRemainingSpaceGib($remainingSpaceGib); + $expectedResponse->setSnapshotEnabled($snapshotEnabled); + $expectedResponse->setPod($pod); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/updateVolumeTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $volume = new Volume(); + $request = (new UpdateVolumeRequest()) + ->setVolume($volume); + $response = $gapicClient->updateVolume($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.baremetalsolution.v2.BareMetalSolution/UpdateVolume', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getVolume(); + $this->assertProtobufEquals($volume, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateVolumeTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function updateVolumeExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/updateVolumeTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $volume = new Volume(); + $request = (new UpdateVolumeRequest()) + ->setVolume($volume); + $response = $gapicClient->updateVolume($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateVolumeTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function detachLunAsyncTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/detachLunTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $id = 'id3355'; + $machineType = 'machineType1838323762'; + $hyperthreadingEnabled = true; + $interactiveSerialConsoleEnabled = false; + $osImage = 'osImage1982209856'; + $pod = 'pod111173'; + $networkTemplate = 'networkTemplate215365483'; + $expectedResponse = new Instance(); + $expectedResponse->setName($name); + $expectedResponse->setId($id); + $expectedResponse->setMachineType($machineType); + $expectedResponse->setHyperthreadingEnabled($hyperthreadingEnabled); + $expectedResponse->setInteractiveSerialConsoleEnabled($interactiveSerialConsoleEnabled); + $expectedResponse->setOsImage($osImage); + $expectedResponse->setPod($pod); + $expectedResponse->setNetworkTemplate($networkTemplate); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/detachLunTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedInstance = $gapicClient->instanceName('[PROJECT]', '[LOCATION]', '[INSTANCE]'); + $formattedLun = $gapicClient->lunName('[PROJECT]', '[LOCATION]', '[VOLUME]', '[LUN]'); + $request = (new DetachLunRequest()) + ->setInstance($formattedInstance) + ->setLun($formattedLun); + $response = $gapicClient->detachLunAsync($request)->wait(); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.baremetalsolution.v2.BareMetalSolution/DetachLun', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getInstance(); + $this->assertProtobufEquals($formattedInstance, $actualValue); + $actualValue = $actualApiRequestObject->getLun(); + $this->assertProtobufEquals($formattedLun, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/detachLunTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } +} diff --git a/Batch/metadata/V1/Job.php b/Batch/metadata/V1/Job.php index 562591488590..78c19edd6759 100644 Binary files a/Batch/metadata/V1/Job.php and b/Batch/metadata/V1/Job.php differ diff --git a/Batch/metadata/V1/Task.php b/Batch/metadata/V1/Task.php index c9fc730172c3..c419878122f9 100644 Binary files a/Batch/metadata/V1/Task.php and b/Batch/metadata/V1/Task.php differ diff --git a/Batch/samples/V1/BatchServiceClient/create_job.php b/Batch/samples/V1/BatchServiceClient/create_job.php index 991cf626dd63..934c0ac7a216 100644 --- a/Batch/samples/V1/BatchServiceClient/create_job.php +++ b/Batch/samples/V1/BatchServiceClient/create_job.php @@ -24,7 +24,8 @@ // [START batch_v1_generated_BatchService_CreateJob_sync] use Google\ApiCore\ApiException; -use Google\Cloud\Batch\V1\BatchServiceClient; +use Google\Cloud\Batch\V1\Client\BatchServiceClient; +use Google\Cloud\Batch\V1\CreateJobRequest; use Google\Cloud\Batch\V1\Job; use Google\Cloud\Batch\V1\TaskGroup; use Google\Cloud\Batch\V1\TaskSpec; @@ -41,18 +42,21 @@ function create_job_sample(string $formattedParent): void // Create a client. $batchServiceClient = new BatchServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $jobTaskGroupsTaskSpec = new TaskSpec(); $taskGroup = (new TaskGroup()) ->setTaskSpec($jobTaskGroupsTaskSpec); $jobTaskGroups = [$taskGroup,]; $job = (new Job()) ->setTaskGroups($jobTaskGroups); + $request = (new CreateJobRequest()) + ->setParent($formattedParent) + ->setJob($job); // Call the API and handle any network failures. try { /** @var Job $response */ - $response = $batchServiceClient->createJob($formattedParent, $job); + $response = $batchServiceClient->createJob($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/Batch/samples/V1/BatchServiceClient/delete_job.php b/Batch/samples/V1/BatchServiceClient/delete_job.php index a0bdd2e14198..77f3076ec644 100644 --- a/Batch/samples/V1/BatchServiceClient/delete_job.php +++ b/Batch/samples/V1/BatchServiceClient/delete_job.php @@ -25,7 +25,8 @@ // [START batch_v1_generated_BatchService_DeleteJob_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\Batch\V1\BatchServiceClient; +use Google\Cloud\Batch\V1\Client\BatchServiceClient; +use Google\Cloud\Batch\V1\DeleteJobRequest; use Google\Rpc\Status; /** @@ -42,10 +43,13 @@ function delete_job_sample(): void // Create a client. $batchServiceClient = new BatchServiceClient(); + // Prepare the request message. + $request = new DeleteJobRequest(); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $batchServiceClient->deleteJob(); + $response = $batchServiceClient->deleteJob($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/Batch/samples/V1/BatchServiceClient/get_job.php b/Batch/samples/V1/BatchServiceClient/get_job.php index a8ecbe7902ad..1214ecab96f4 100644 --- a/Batch/samples/V1/BatchServiceClient/get_job.php +++ b/Batch/samples/V1/BatchServiceClient/get_job.php @@ -24,7 +24,8 @@ // [START batch_v1_generated_BatchService_GetJob_sync] use Google\ApiCore\ApiException; -use Google\Cloud\Batch\V1\BatchServiceClient; +use Google\Cloud\Batch\V1\Client\BatchServiceClient; +use Google\Cloud\Batch\V1\GetJobRequest; use Google\Cloud\Batch\V1\Job; /** @@ -38,10 +39,14 @@ function get_job_sample(string $formattedName): void // Create a client. $batchServiceClient = new BatchServiceClient(); + // Prepare the request message. + $request = (new GetJobRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var Job $response */ - $response = $batchServiceClient->getJob($formattedName); + $response = $batchServiceClient->getJob($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/Batch/samples/V1/BatchServiceClient/get_location.php b/Batch/samples/V1/BatchServiceClient/get_location.php index e0111df3de2d..9c4f203431bb 100644 --- a/Batch/samples/V1/BatchServiceClient/get_location.php +++ b/Batch/samples/V1/BatchServiceClient/get_location.php @@ -24,7 +24,8 @@ // [START batch_v1_generated_BatchService_GetLocation_sync] use Google\ApiCore\ApiException; -use Google\Cloud\Batch\V1\BatchServiceClient; +use Google\Cloud\Batch\V1\Client\BatchServiceClient; +use Google\Cloud\Location\GetLocationRequest; use Google\Cloud\Location\Location; /** @@ -41,10 +42,13 @@ function get_location_sample(): void // Create a client. $batchServiceClient = new BatchServiceClient(); + // Prepare the request message. + $request = new GetLocationRequest(); + // Call the API and handle any network failures. try { /** @var Location $response */ - $response = $batchServiceClient->getLocation(); + $response = $batchServiceClient->getLocation($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/Batch/samples/V1/BatchServiceClient/get_task.php b/Batch/samples/V1/BatchServiceClient/get_task.php index aef0951f5fe6..5ef1d86cd668 100644 --- a/Batch/samples/V1/BatchServiceClient/get_task.php +++ b/Batch/samples/V1/BatchServiceClient/get_task.php @@ -24,7 +24,8 @@ // [START batch_v1_generated_BatchService_GetTask_sync] use Google\ApiCore\ApiException; -use Google\Cloud\Batch\V1\BatchServiceClient; +use Google\Cloud\Batch\V1\Client\BatchServiceClient; +use Google\Cloud\Batch\V1\GetTaskRequest; use Google\Cloud\Batch\V1\Task; /** @@ -38,10 +39,14 @@ function get_task_sample(string $formattedName): void // Create a client. $batchServiceClient = new BatchServiceClient(); + // Prepare the request message. + $request = (new GetTaskRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var Task $response */ - $response = $batchServiceClient->getTask($formattedName); + $response = $batchServiceClient->getTask($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/Batch/samples/V1/BatchServiceClient/list_jobs.php b/Batch/samples/V1/BatchServiceClient/list_jobs.php index fab86df47e46..4113b01dae98 100644 --- a/Batch/samples/V1/BatchServiceClient/list_jobs.php +++ b/Batch/samples/V1/BatchServiceClient/list_jobs.php @@ -25,8 +25,9 @@ // [START batch_v1_generated_BatchService_ListJobs_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; -use Google\Cloud\Batch\V1\BatchServiceClient; +use Google\Cloud\Batch\V1\Client\BatchServiceClient; use Google\Cloud\Batch\V1\Job; +use Google\Cloud\Batch\V1\ListJobsRequest; /** * List all Jobs for a project within a region. @@ -42,10 +43,13 @@ function list_jobs_sample(): void // Create a client. $batchServiceClient = new BatchServiceClient(); + // Prepare the request message. + $request = new ListJobsRequest(); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $batchServiceClient->listJobs(); + $response = $batchServiceClient->listJobs($request); /** @var Job $element */ foreach ($response as $element) { diff --git a/Batch/samples/V1/BatchServiceClient/list_locations.php b/Batch/samples/V1/BatchServiceClient/list_locations.php index 13ecc80c17d8..afdd8f478b9e 100644 --- a/Batch/samples/V1/BatchServiceClient/list_locations.php +++ b/Batch/samples/V1/BatchServiceClient/list_locations.php @@ -25,7 +25,8 @@ // [START batch_v1_generated_BatchService_ListLocations_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; -use Google\Cloud\Batch\V1\BatchServiceClient; +use Google\Cloud\Batch\V1\Client\BatchServiceClient; +use Google\Cloud\Location\ListLocationsRequest; use Google\Cloud\Location\Location; /** @@ -42,10 +43,13 @@ function list_locations_sample(): void // Create a client. $batchServiceClient = new BatchServiceClient(); + // Prepare the request message. + $request = new ListLocationsRequest(); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $batchServiceClient->listLocations(); + $response = $batchServiceClient->listLocations($request); /** @var Location $element */ foreach ($response as $element) { diff --git a/Batch/samples/V1/BatchServiceClient/list_tasks.php b/Batch/samples/V1/BatchServiceClient/list_tasks.php index 3b7f3b1a700d..66aa3eec1521 100644 --- a/Batch/samples/V1/BatchServiceClient/list_tasks.php +++ b/Batch/samples/V1/BatchServiceClient/list_tasks.php @@ -25,7 +25,8 @@ // [START batch_v1_generated_BatchService_ListTasks_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; -use Google\Cloud\Batch\V1\BatchServiceClient; +use Google\Cloud\Batch\V1\Client\BatchServiceClient; +use Google\Cloud\Batch\V1\ListTasksRequest; use Google\Cloud\Batch\V1\Task; /** @@ -41,10 +42,14 @@ function list_tasks_sample(string $formattedParent): void // Create a client. $batchServiceClient = new BatchServiceClient(); + // Prepare the request message. + $request = (new ListTasksRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $batchServiceClient->listTasks($formattedParent); + $response = $batchServiceClient->listTasks($request); /** @var Task $element */ foreach ($response as $element) { diff --git a/Batch/src/V1/AllocationPolicy.php b/Batch/src/V1/AllocationPolicy.php index a5b131887262..fc11281b6242 100644 --- a/Batch/src/V1/AllocationPolicy.php +++ b/Batch/src/V1/AllocationPolicy.php @@ -53,6 +53,12 @@ class AllocationPolicy extends \Google\Protobuf\Internal\Message * Generated from protobuf field .google.cloud.batch.v1.AllocationPolicy.NetworkPolicy network = 7; */ private $network = null; + /** + * The placement policy. + * + * Generated from protobuf field .google.cloud.batch.v1.AllocationPolicy.PlacementPolicy placement = 10; + */ + private $placement = null; /** * Constructor. @@ -77,6 +83,8 @@ class AllocationPolicy extends \Google\Protobuf\Internal\Message * Label names that start with "goog-" or "google-" are reserved. * @type \Google\Cloud\Batch\V1\AllocationPolicy\NetworkPolicy $network * The network policy. + * @type \Google\Cloud\Batch\V1\AllocationPolicy\PlacementPolicy $placement + * The placement policy. * } */ public function __construct($data = NULL) { @@ -258,5 +266,41 @@ public function setNetwork($var) return $this; } + /** + * The placement policy. + * + * Generated from protobuf field .google.cloud.batch.v1.AllocationPolicy.PlacementPolicy placement = 10; + * @return \Google\Cloud\Batch\V1\AllocationPolicy\PlacementPolicy|null + */ + public function getPlacement() + { + return $this->placement; + } + + public function hasPlacement() + { + return isset($this->placement); + } + + public function clearPlacement() + { + unset($this->placement); + } + + /** + * The placement policy. + * + * Generated from protobuf field .google.cloud.batch.v1.AllocationPolicy.PlacementPolicy placement = 10; + * @param \Google\Cloud\Batch\V1\AllocationPolicy\PlacementPolicy $var + * @return $this + */ + public function setPlacement($var) + { + GPBUtil::checkMessage($var, \Google\Cloud\Batch\V1\AllocationPolicy\PlacementPolicy::class); + $this->placement = $var; + + return $this; + } + } diff --git a/Batch/src/V1/AllocationPolicy/Disk.php b/Batch/src/V1/AllocationPolicy/Disk.php index 3dac8012d246..2764152b62d2 100644 --- a/Batch/src/V1/AllocationPolicy/Disk.php +++ b/Batch/src/V1/AllocationPolicy/Disk.php @@ -11,7 +11,7 @@ /** * A new persistent disk or a local ssd. * A VM can only have one local SSD setting but multiple local SSD partitions. - * https://cloud.google.com/compute/docs/disks#pdspecs. + * See https://cloud.google.com/compute/docs/disks#pdspecs and * https://cloud.google.com/compute/docs/disks#localssds. * * Generated from protobuf message google.cloud.batch.v1.AllocationPolicy.Disk @@ -60,17 +60,18 @@ class Disk extends \Google\Protobuf\Internal\Message * @type string $image * Name of a public or custom image used as the data source. * For example, the following are all valid URLs: - * (1) Specify the image by its family name: + * * Specify the image by its family name: * projects/{project}/global/images/family/{image_family} - * (2) Specify the image version: + * * Specify the image version: * projects/{project}/global/images/{image_version} * You can also use Batch customized image in short names. * The following image values are supported for a boot disk: - * "batch-debian": use Batch Debian images. - * "batch-centos": use Batch CentOS images. - * "batch-cos": use Batch Container-Optimized images. + * * "batch-debian": use Batch Debian images. + * * "batch-centos": use Batch CentOS images. + * * "batch-cos": use Batch Container-Optimized images. * @type string $snapshot * Name of a snapshot used as the data source. + * Snapshot is not supported as boot disk now. * @type string $type * Disk type as shown in `gcloud compute disk-types list`. * For example, local SSD uses type "local-ssd". @@ -100,15 +101,15 @@ public function __construct($data = NULL) { /** * Name of a public or custom image used as the data source. * For example, the following are all valid URLs: - * (1) Specify the image by its family name: + * * Specify the image by its family name: * projects/{project}/global/images/family/{image_family} - * (2) Specify the image version: + * * Specify the image version: * projects/{project}/global/images/{image_version} * You can also use Batch customized image in short names. * The following image values are supported for a boot disk: - * "batch-debian": use Batch Debian images. - * "batch-centos": use Batch CentOS images. - * "batch-cos": use Batch Container-Optimized images. + * * "batch-debian": use Batch Debian images. + * * "batch-centos": use Batch CentOS images. + * * "batch-cos": use Batch Container-Optimized images. * * Generated from protobuf field string image = 4; * @return string @@ -126,15 +127,15 @@ public function hasImage() /** * Name of a public or custom image used as the data source. * For example, the following are all valid URLs: - * (1) Specify the image by its family name: + * * Specify the image by its family name: * projects/{project}/global/images/family/{image_family} - * (2) Specify the image version: + * * Specify the image version: * projects/{project}/global/images/{image_version} * You can also use Batch customized image in short names. * The following image values are supported for a boot disk: - * "batch-debian": use Batch Debian images. - * "batch-centos": use Batch CentOS images. - * "batch-cos": use Batch Container-Optimized images. + * * "batch-debian": use Batch Debian images. + * * "batch-centos": use Batch CentOS images. + * * "batch-cos": use Batch Container-Optimized images. * * Generated from protobuf field string image = 4; * @param string $var @@ -150,6 +151,7 @@ public function setImage($var) /** * Name of a snapshot used as the data source. + * Snapshot is not supported as boot disk now. * * Generated from protobuf field string snapshot = 5; * @return string @@ -166,6 +168,7 @@ public function hasSnapshot() /** * Name of a snapshot used as the data source. + * Snapshot is not supported as boot disk now. * * Generated from protobuf field string snapshot = 5; * @param string $var diff --git a/Batch/src/V1/AllocationPolicy/InstancePolicy.php b/Batch/src/V1/AllocationPolicy/InstancePolicy.php index 43a679d243d2..f7b1e9b7d957 100644 --- a/Batch/src/V1/AllocationPolicy/InstancePolicy.php +++ b/Batch/src/V1/AllocationPolicy/InstancePolicy.php @@ -25,7 +25,7 @@ class InstancePolicy extends \Google\Protobuf\Internal\Message /** * The minimum CPU platform. * See - * `https://cloud.google.com/compute/docs/instances/specify-min-cpu-platform`. + * https://cloud.google.com/compute/docs/instances/specify-min-cpu-platform. * Not yet implemented. * * Generated from protobuf field string min_cpu_platform = 3; @@ -44,8 +44,9 @@ class InstancePolicy extends \Google\Protobuf\Internal\Message */ private $accelerators; /** - * Book disk to be created and attached to each VM by this InstancePolicy. + * Boot disk to be created and attached to each VM by this InstancePolicy. * Boot disk will be deleted when the VM is deleted. + * Batch API now only supports booting from image. * * Generated from protobuf field .google.cloud.batch.v1.AllocationPolicy.Disk boot_disk = 8; */ @@ -69,15 +70,16 @@ class InstancePolicy extends \Google\Protobuf\Internal\Message * @type string $min_cpu_platform * The minimum CPU platform. * See - * `https://cloud.google.com/compute/docs/instances/specify-min-cpu-platform`. + * https://cloud.google.com/compute/docs/instances/specify-min-cpu-platform. * Not yet implemented. * @type int $provisioning_model * The provisioning model. * @type array<\Google\Cloud\Batch\V1\AllocationPolicy\Accelerator>|\Google\Protobuf\Internal\RepeatedField $accelerators * The accelerators attached to each VM instance. * @type \Google\Cloud\Batch\V1\AllocationPolicy\Disk $boot_disk - * Book disk to be created and attached to each VM by this InstancePolicy. + * Boot disk to be created and attached to each VM by this InstancePolicy. * Boot disk will be deleted when the VM is deleted. + * Batch API now only supports booting from image. * @type array<\Google\Cloud\Batch\V1\AllocationPolicy\AttachedDisk>|\Google\Protobuf\Internal\RepeatedField $disks * Non-boot disks to be attached for each VM created by this InstancePolicy. * New disks will be deleted when the VM is deleted. @@ -117,7 +119,7 @@ public function setMachineType($var) /** * The minimum CPU platform. * See - * `https://cloud.google.com/compute/docs/instances/specify-min-cpu-platform`. + * https://cloud.google.com/compute/docs/instances/specify-min-cpu-platform. * Not yet implemented. * * Generated from protobuf field string min_cpu_platform = 3; @@ -131,7 +133,7 @@ public function getMinCpuPlatform() /** * The minimum CPU platform. * See - * `https://cloud.google.com/compute/docs/instances/specify-min-cpu-platform`. + * https://cloud.google.com/compute/docs/instances/specify-min-cpu-platform. * Not yet implemented. * * Generated from protobuf field string min_cpu_platform = 3; @@ -199,8 +201,9 @@ public function setAccelerators($var) } /** - * Book disk to be created and attached to each VM by this InstancePolicy. + * Boot disk to be created and attached to each VM by this InstancePolicy. * Boot disk will be deleted when the VM is deleted. + * Batch API now only supports booting from image. * * Generated from protobuf field .google.cloud.batch.v1.AllocationPolicy.Disk boot_disk = 8; * @return \Google\Cloud\Batch\V1\AllocationPolicy\Disk|null @@ -221,8 +224,9 @@ public function clearBootDisk() } /** - * Book disk to be created and attached to each VM by this InstancePolicy. + * Boot disk to be created and attached to each VM by this InstancePolicy. * Boot disk will be deleted when the VM is deleted. + * Batch API now only supports booting from image. * * Generated from protobuf field .google.cloud.batch.v1.AllocationPolicy.Disk boot_disk = 8; * @param \Google\Cloud\Batch\V1\AllocationPolicy\Disk $var diff --git a/Batch/src/V1/AllocationPolicy/NetworkInterface.php b/Batch/src/V1/AllocationPolicy/NetworkInterface.php index f92a563a97f0..76d3ab4b804e 100644 --- a/Batch/src/V1/AllocationPolicy/NetworkInterface.php +++ b/Batch/src/V1/AllocationPolicy/NetworkInterface.php @@ -19,9 +19,9 @@ class NetworkInterface extends \Google\Protobuf\Internal\Message * The URL of an existing network resource. * You can specify the network as a full or partial URL. * For example, the following are all valid URLs: - * https://www.googleapis.com/compute/v1/projects/{project}/global/networks/{network} - * projects/{project}/global/networks/{network} - * global/networks/{network} + * * https://www.googleapis.com/compute/v1/projects/{project}/global/networks/{network} + * * projects/{project}/global/networks/{network} + * * global/networks/{network} * * Generated from protobuf field string network = 1; */ @@ -30,9 +30,9 @@ class NetworkInterface extends \Google\Protobuf\Internal\Message * The URL of an existing subnetwork resource in the network. * You can specify the subnetwork as a full or partial URL. * For example, the following are all valid URLs: - * https://www.googleapis.com/compute/v1/projects/{project}/regions/{region}/subnetworks/{subnetwork} - * projects/{project}/regions/{region}/subnetworks/{subnetwork} - * regions/{region}/subnetworks/{subnetwork} + * * https://www.googleapis.com/compute/v1/projects/{project}/regions/{region}/subnetworks/{subnetwork} + * * projects/{project}/regions/{region}/subnetworks/{subnetwork} + * * regions/{region}/subnetworks/{subnetwork} * * Generated from protobuf field string subnetwork = 2; */ @@ -60,16 +60,16 @@ class NetworkInterface extends \Google\Protobuf\Internal\Message * The URL of an existing network resource. * You can specify the network as a full or partial URL. * For example, the following are all valid URLs: - * https://www.googleapis.com/compute/v1/projects/{project}/global/networks/{network} - * projects/{project}/global/networks/{network} - * global/networks/{network} + * * https://www.googleapis.com/compute/v1/projects/{project}/global/networks/{network} + * * projects/{project}/global/networks/{network} + * * global/networks/{network} * @type string $subnetwork * The URL of an existing subnetwork resource in the network. * You can specify the subnetwork as a full or partial URL. * For example, the following are all valid URLs: - * https://www.googleapis.com/compute/v1/projects/{project}/regions/{region}/subnetworks/{subnetwork} - * projects/{project}/regions/{region}/subnetworks/{subnetwork} - * regions/{region}/subnetworks/{subnetwork} + * * https://www.googleapis.com/compute/v1/projects/{project}/regions/{region}/subnetworks/{subnetwork} + * * projects/{project}/regions/{region}/subnetworks/{subnetwork} + * * regions/{region}/subnetworks/{subnetwork} * @type bool $no_external_ip_address * Default is false (with an external IP address). Required if * no external public IP address is attached to the VM. If no external @@ -89,9 +89,9 @@ public function __construct($data = NULL) { * The URL of an existing network resource. * You can specify the network as a full or partial URL. * For example, the following are all valid URLs: - * https://www.googleapis.com/compute/v1/projects/{project}/global/networks/{network} - * projects/{project}/global/networks/{network} - * global/networks/{network} + * * https://www.googleapis.com/compute/v1/projects/{project}/global/networks/{network} + * * projects/{project}/global/networks/{network} + * * global/networks/{network} * * Generated from protobuf field string network = 1; * @return string @@ -105,9 +105,9 @@ public function getNetwork() * The URL of an existing network resource. * You can specify the network as a full or partial URL. * For example, the following are all valid URLs: - * https://www.googleapis.com/compute/v1/projects/{project}/global/networks/{network} - * projects/{project}/global/networks/{network} - * global/networks/{network} + * * https://www.googleapis.com/compute/v1/projects/{project}/global/networks/{network} + * * projects/{project}/global/networks/{network} + * * global/networks/{network} * * Generated from protobuf field string network = 1; * @param string $var @@ -125,9 +125,9 @@ public function setNetwork($var) * The URL of an existing subnetwork resource in the network. * You can specify the subnetwork as a full or partial URL. * For example, the following are all valid URLs: - * https://www.googleapis.com/compute/v1/projects/{project}/regions/{region}/subnetworks/{subnetwork} - * projects/{project}/regions/{region}/subnetworks/{subnetwork} - * regions/{region}/subnetworks/{subnetwork} + * * https://www.googleapis.com/compute/v1/projects/{project}/regions/{region}/subnetworks/{subnetwork} + * * projects/{project}/regions/{region}/subnetworks/{subnetwork} + * * regions/{region}/subnetworks/{subnetwork} * * Generated from protobuf field string subnetwork = 2; * @return string @@ -141,9 +141,9 @@ public function getSubnetwork() * The URL of an existing subnetwork resource in the network. * You can specify the subnetwork as a full or partial URL. * For example, the following are all valid URLs: - * https://www.googleapis.com/compute/v1/projects/{project}/regions/{region}/subnetworks/{subnetwork} - * projects/{project}/regions/{region}/subnetworks/{subnetwork} - * regions/{region}/subnetworks/{subnetwork} + * * https://www.googleapis.com/compute/v1/projects/{project}/regions/{region}/subnetworks/{subnetwork} + * * projects/{project}/regions/{region}/subnetworks/{subnetwork} + * * regions/{region}/subnetworks/{subnetwork} * * Generated from protobuf field string subnetwork = 2; * @param string $var diff --git a/Batch/src/V1/AllocationPolicy/PlacementPolicy.php b/Batch/src/V1/AllocationPolicy/PlacementPolicy.php new file mode 100644 index 000000000000..080402eb1f91 --- /dev/null +++ b/Batch/src/V1/AllocationPolicy/PlacementPolicy.php @@ -0,0 +1,131 @@ +google.cloud.batch.v1.AllocationPolicy.PlacementPolicy + */ +class PlacementPolicy extends \Google\Protobuf\Internal\Message +{ + /** + * UNSPECIFIED vs. COLLOCATED (default UNSPECIFIED). Use COLLOCATED when you + * want VMs to be located close to each other for low network latency + * between the VMs. No placement policy will be generated when collocation + * is UNSPECIFIED. + * + * Generated from protobuf field string collocation = 1; + */ + private $collocation = ''; + /** + * When specified, causes the job to fail if more than max_distance logical + * switches are required between VMs. Batch uses the most compact possible + * placement of VMs even when max_distance is not specified. An explicit + * max_distance makes that level of compactness a strict requirement. + * Not yet implemented + * + * Generated from protobuf field int64 max_distance = 2; + */ + private $max_distance = 0; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $collocation + * UNSPECIFIED vs. COLLOCATED (default UNSPECIFIED). Use COLLOCATED when you + * want VMs to be located close to each other for low network latency + * between the VMs. No placement policy will be generated when collocation + * is UNSPECIFIED. + * @type int|string $max_distance + * When specified, causes the job to fail if more than max_distance logical + * switches are required between VMs. Batch uses the most compact possible + * placement of VMs even when max_distance is not specified. An explicit + * max_distance makes that level of compactness a strict requirement. + * Not yet implemented + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Batch\V1\Job::initOnce(); + parent::__construct($data); + } + + /** + * UNSPECIFIED vs. COLLOCATED (default UNSPECIFIED). Use COLLOCATED when you + * want VMs to be located close to each other for low network latency + * between the VMs. No placement policy will be generated when collocation + * is UNSPECIFIED. + * + * Generated from protobuf field string collocation = 1; + * @return string + */ + public function getCollocation() + { + return $this->collocation; + } + + /** + * UNSPECIFIED vs. COLLOCATED (default UNSPECIFIED). Use COLLOCATED when you + * want VMs to be located close to each other for low network latency + * between the VMs. No placement policy will be generated when collocation + * is UNSPECIFIED. + * + * Generated from protobuf field string collocation = 1; + * @param string $var + * @return $this + */ + public function setCollocation($var) + { + GPBUtil::checkString($var, True); + $this->collocation = $var; + + return $this; + } + + /** + * When specified, causes the job to fail if more than max_distance logical + * switches are required between VMs. Batch uses the most compact possible + * placement of VMs even when max_distance is not specified. An explicit + * max_distance makes that level of compactness a strict requirement. + * Not yet implemented + * + * Generated from protobuf field int64 max_distance = 2; + * @return int|string + */ + public function getMaxDistance() + { + return $this->max_distance; + } + + /** + * When specified, causes the job to fail if more than max_distance logical + * switches are required between VMs. Batch uses the most compact possible + * placement of VMs even when max_distance is not specified. An explicit + * max_distance makes that level of compactness a strict requirement. + * Not yet implemented + * + * Generated from protobuf field int64 max_distance = 2; + * @param int|string $var + * @return $this + */ + public function setMaxDistance($var) + { + GPBUtil::checkInt64($var); + $this->max_distance = $var; + + return $this; + } + +} + + diff --git a/Batch/src/V1/Client/BaseClient/BatchServiceBaseClient.php b/Batch/src/V1/Client/BaseClient/BatchServiceBaseClient.php new file mode 100644 index 000000000000..a1d8c3233f3c --- /dev/null +++ b/Batch/src/V1/Client/BaseClient/BatchServiceBaseClient.php @@ -0,0 +1,522 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/batch_service_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/batch_service_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/batch_service_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/batch_service_rest_client_config.php', + ], + ], + ]; + } + + /** + * Return an OperationsClient object with the same endpoint as $this. + * + * @return OperationsClient + */ + public function getOperationsClient() + { + return $this->operationsClient; + } + + /** + * Resume an existing long running operation that was previously started by a long + * running API method. If $methodName is not provided, or does not match a long + * running API method, then the operation can still be resumed, but the + * OperationResponse object will not deserialize the final response. + * + * @param string $operationName The name of the long running operation + * @param string $methodName The name of the method used to start the operation + * + * @return OperationResponse + */ + public function resumeOperation($operationName, $methodName = null) + { + $options = isset($this->descriptors[$methodName]['longRunning']) ? $this->descriptors[$methodName]['longRunning'] : []; + $operation = new OperationResponse($operationName, $this->getOperationsClient(), $options); + $operation->reload(); + return $operation; + } + + /** + * Formats a string containing the fully-qualified path to represent a job + * resource. + * + * @param string $project + * @param string $location + * @param string $job + * + * @return string The formatted job resource. + */ + public static function jobName(string $project, string $location, string $job): string + { + return self::getPathTemplate('job')->render([ + 'project' => $project, + 'location' => $location, + 'job' => $job, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a location + * resource. + * + * @param string $project + * @param string $location + * + * @return string The formatted location resource. + */ + public static function locationName(string $project, string $location): string + { + return self::getPathTemplate('location')->render([ + 'project' => $project, + 'location' => $location, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a task + * resource. + * + * @param string $project + * @param string $location + * @param string $job + * @param string $taskGroup + * @param string $task + * + * @return string The formatted task resource. + */ + public static function taskName(string $project, string $location, string $job, string $taskGroup, string $task): string + { + return self::getPathTemplate('task')->render([ + 'project' => $project, + 'location' => $location, + 'job' => $job, + 'task_group' => $taskGroup, + 'task' => $task, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a task_group + * resource. + * + * @param string $project + * @param string $location + * @param string $job + * @param string $taskGroup + * + * @return string The formatted task_group resource. + */ + public static function taskGroupName(string $project, string $location, string $job, string $taskGroup): string + { + return self::getPathTemplate('taskGroup')->render([ + 'project' => $project, + 'location' => $location, + 'job' => $job, + 'task_group' => $taskGroup, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * Template: Pattern + * - job: projects/{project}/locations/{location}/jobs/{job} + * - location: projects/{project}/locations/{location} + * - task: projects/{project}/locations/{location}/jobs/{job}/taskGroups/{task_group}/tasks/{task} + * - taskGroup: projects/{project}/locations/{location}/jobs/{job}/taskGroups/{task_group} + * + * The optional $template argument can be supplied to specify a particular pattern, + * and must match one of the templates listed above. If no $template argument is + * provided, or if the $template argument does not match one of the templates + * listed, then parseName will check each of the supported templates, and return + * the first match. + * + * @param string $formattedName The formatted name string + * @param string $template Optional name of template to match + * + * @return array An associative array from name component IDs to component values. + * + * @throws ValidationException If $formattedName could not be matched. + */ + public static function parseName(string $formattedName, string $template = null): array + { + return self::parseFormattedName($formattedName, $template); + } + + /** + * Constructor. + * + * @param array $options { + * Optional. Options for configuring the service API wrapper. + * + * @type string $apiEndpoint + * The address of the API remote host. May optionally include the port, formatted + * as ":". Default 'batch.googleapis.com:443'. + * @type string|array|FetchAuthTokenInterface|CredentialsWrapper $credentials + * The credentials to be used by the client to authorize API calls. This option + * accepts either a path to a credentials file, or a decoded credentials file as a + * PHP array. + * *Advanced usage*: In addition, this option can also accept a pre-constructed + * {@see \Google\Auth\FetchAuthTokenInterface} object or + * {@see \Google\ApiCore\CredentialsWrapper} object. Note that when one of these + * objects are provided, any settings in $credentialsConfig will be ignored. + * @type array $credentialsConfig + * Options used to configure credentials, including auth token caching, for the + * client. For a full list of supporting configuration options, see + * {@see \Google\ApiCore\CredentialsWrapper::build()} . + * @type bool $disableRetries + * Determines whether or not retries defined by the client configuration should be + * disabled. Defaults to `false`. + * @type string|array $clientConfig + * Client method configuration, including retry settings. This option can be either + * a path to a JSON file, or a PHP array containing the decoded JSON data. By + * default this settings points to the default client config file, which is + * provided in the resources folder. + * @type string|TransportInterface $transport + * The transport used for executing network requests. May be either the string + * `rest` or `grpc`. Defaults to `grpc` if gRPC support is detected on the system. + * *Advanced usage*: Additionally, it is possible to pass in an already + * instantiated {@see \Google\ApiCore\Transport\TransportInterface} object. Note + * that when this object is provided, any settings in $transportConfig, and any + * $apiEndpoint setting, will be ignored. + * @type array $transportConfig + * Configuration options that will be used to construct the transport. Options for + * each supported transport type should be passed in a key for that transport. For + * example: + * $transportConfig = [ + * 'grpc' => [...], + * 'rest' => [...], + * ]; + * See the {@see \Google\ApiCore\Transport\GrpcTransport::build()} and + * {@see \Google\ApiCore\Transport\RestTransport::build()} methods for the + * supported options. + * @type callable $clientCertSource + * A callable which returns the client cert as a string. This can be used to + * provide a certificate and private key to the transport layer for mTLS. + * } + * + * @throws ValidationException + */ + public function __construct(array $options = []) + { + $clientOptions = $this->buildClientOptions($options); + $this->setClientOptions($clientOptions); + $this->operationsClient = $this->createOperationsClient($clientOptions); + } + + /** Handles execution of the async variants for each documented method. */ + public function __call($method, $args) + { + if (substr($method, -5) !== 'Async') { + trigger_error('Call to undefined method ' . __CLASS__ . "::$method()", E_USER_ERROR); + } + + array_unshift($args, substr($method, 0, -5)); + return call_user_func_array([$this, 'startAsyncCall'], $args); + } + + /** + * Create a Job. + * + * The async variant is {@see self::createJobAsync()} . + * + * @param CreateJobRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Job + * + * @throws ApiException Thrown if the API call fails. + */ + public function createJob(CreateJobRequest $request, array $callOptions = []): Job + { + return $this->startApiCall('CreateJob', $request, $callOptions)->wait(); + } + + /** + * Delete a Job. + * + * The async variant is {@see self::deleteJobAsync()} . + * + * @param DeleteJobRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function deleteJob(DeleteJobRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('DeleteJob', $request, $callOptions)->wait(); + } + + /** + * Get a Job specified by its resource name. + * + * The async variant is {@see self::getJobAsync()} . + * + * @param GetJobRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Job + * + * @throws ApiException Thrown if the API call fails. + */ + public function getJob(GetJobRequest $request, array $callOptions = []): Job + { + return $this->startApiCall('GetJob', $request, $callOptions)->wait(); + } + + /** + * Return a single Task. + * + * The async variant is {@see self::getTaskAsync()} . + * + * @param GetTaskRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Task + * + * @throws ApiException Thrown if the API call fails. + */ + public function getTask(GetTaskRequest $request, array $callOptions = []): Task + { + return $this->startApiCall('GetTask', $request, $callOptions)->wait(); + } + + /** + * List all Jobs for a project within a region. + * + * The async variant is {@see self::listJobsAsync()} . + * + * @param ListJobsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listJobs(ListJobsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListJobs', $request, $callOptions); + } + + /** + * List Tasks associated with a job. + * + * The async variant is {@see self::listTasksAsync()} . + * + * @param ListTasksRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listTasks(ListTasksRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListTasks', $request, $callOptions); + } + + /** + * Gets information about a location. + * + * The async variant is {@see self::getLocationAsync()} . + * + * @param GetLocationRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Location + * + * @throws ApiException Thrown if the API call fails. + */ + public function getLocation(GetLocationRequest $request, array $callOptions = []): Location + { + return $this->startApiCall('GetLocation', $request, $callOptions)->wait(); + } + + /** + * Lists information about the supported locations for this service. + * + * The async variant is {@see self::listLocationsAsync()} . + * + * @param ListLocationsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listLocations(ListLocationsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListLocations', $request, $callOptions); + } +} diff --git a/Batch/src/V1/Client/BatchServiceClient.php b/Batch/src/V1/Client/BatchServiceClient.php new file mode 100644 index 000000000000..5fb6c3bd3c1e --- /dev/null +++ b/Batch/src/V1/Client/BatchServiceClient.php @@ -0,0 +1,40 @@ +setParent($parent) + ->setJob($job) + ->setJobId($jobId); + } + /** * Constructor. * diff --git a/Batch/src/V1/DeleteJobRequest.php b/Batch/src/V1/DeleteJobRequest.php index 2971ff2ea860..76843ae7e020 100644 --- a/Batch/src/V1/DeleteJobRequest.php +++ b/Batch/src/V1/DeleteJobRequest.php @@ -44,6 +44,19 @@ class DeleteJobRequest extends \Google\Protobuf\Internal\Message */ private $request_id = ''; + /** + * @param string $name Job name. + * + * @return \Google\Cloud\Batch\V1\DeleteJobRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/Batch/src/V1/GetJobRequest.php b/Batch/src/V1/GetJobRequest.php index a14d47d59368..6bd20c416e71 100644 --- a/Batch/src/V1/GetJobRequest.php +++ b/Batch/src/V1/GetJobRequest.php @@ -22,6 +22,20 @@ class GetJobRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. Job name. Please see + * {@see BatchServiceClient::jobName()} for help formatting this field. + * + * @return \Google\Cloud\Batch\V1\GetJobRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/Batch/src/V1/GetTaskRequest.php b/Batch/src/V1/GetTaskRequest.php index abb7d163e0db..1fcad29bc88e 100644 --- a/Batch/src/V1/GetTaskRequest.php +++ b/Batch/src/V1/GetTaskRequest.php @@ -22,6 +22,20 @@ class GetTaskRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. Task name. Please see + * {@see BatchServiceClient::taskName()} for help formatting this field. + * + * @return \Google\Cloud\Batch\V1\GetTaskRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/Batch/src/V1/ListJobsRequest.php b/Batch/src/V1/ListJobsRequest.php index 142960ab137d..e87b663dd4b5 100644 --- a/Batch/src/V1/ListJobsRequest.php +++ b/Batch/src/V1/ListJobsRequest.php @@ -40,6 +40,19 @@ class ListJobsRequest extends \Google\Protobuf\Internal\Message */ private $page_token = ''; + /** + * @param string $parent Parent path. + * + * @return \Google\Cloud\Batch\V1\ListJobsRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/Batch/src/V1/ListTasksRequest.php b/Batch/src/V1/ListTasksRequest.php index 5764afa4720a..cba6326bf973 100644 --- a/Batch/src/V1/ListTasksRequest.php +++ b/Batch/src/V1/ListTasksRequest.php @@ -44,6 +44,22 @@ class ListTasksRequest extends \Google\Protobuf\Internal\Message */ private $page_token = ''; + /** + * @param string $parent Required. Name of a TaskGroup from which Tasks are being requested. + * Pattern: + * "projects/{project}/locations/{location}/jobs/{job}/taskGroups/{task_group}" + * Please see {@see BatchServiceClient::taskGroupName()} for help formatting this field. + * + * @return \Google\Cloud\Batch\V1\ListTasksRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/Batch/src/V1/Runnable.php b/Batch/src/V1/Runnable.php index f03a6a7e0377..c4f9c2cdc20b 100644 --- a/Batch/src/V1/Runnable.php +++ b/Batch/src/V1/Runnable.php @@ -56,6 +56,12 @@ class Runnable extends \Google\Protobuf\Internal\Message * Generated from protobuf field .google.protobuf.Duration timeout = 8; */ private $timeout = null; + /** + * Labels for this Runnable. + * + * Generated from protobuf field map labels = 9; + */ + private $labels; protected $executable; /** @@ -90,6 +96,8 @@ class Runnable extends \Google\Protobuf\Internal\Message * whole Task or TaskGroup). * @type \Google\Protobuf\Duration $timeout * Timeout for this Runnable. + * @type array|\Google\Protobuf\Internal\MapField $labels + * Labels for this Runnable. * } */ public function __construct($data = NULL) { @@ -360,6 +368,32 @@ public function setTimeout($var) return $this; } + /** + * Labels for this Runnable. + * + * Generated from protobuf field map labels = 9; + * @return \Google\Protobuf\Internal\MapField + */ + public function getLabels() + { + return $this->labels; + } + + /** + * Labels for this Runnable. + * + * Generated from protobuf field map labels = 9; + * @param array|\Google\Protobuf\Internal\MapField $var + * @return $this + */ + public function setLabels($var) + { + $arr = GPBUtil::checkMapField($var, \Google\Protobuf\Internal\GPBType::STRING, \Google\Protobuf\Internal\GPBType::STRING); + $this->labels = $arr; + + return $this; + } + /** * @return string */ diff --git a/Batch/src/V1/Runnable/Container.php b/Batch/src/V1/Runnable/Container.php index 2e2e9a8b7e00..599febc147c4 100644 --- a/Batch/src/V1/Runnable/Container.php +++ b/Batch/src/V1/Runnable/Container.php @@ -52,8 +52,9 @@ class Container extends \Google\Protobuf\Internal\Message private $options = ''; /** * If set to true, external network access to and from container will be - * blocked. The container will use the default internal network - * 'goog-internal'. + * blocked, containers that are with block_external_network as true can + * still communicate with each other, network cannot be specified in the + * `container.options` field. * * Generated from protobuf field bool block_external_network = 9; */ @@ -98,8 +99,9 @@ class Container extends \Google\Protobuf\Internal\Message * running this container, e.g. "--network host". * @type bool $block_external_network * If set to true, external network access to and from container will be - * blocked. The container will use the default internal network - * 'goog-internal'. + * blocked, containers that are with block_external_network as true can + * still communicate with each other, network cannot be specified in the + * `container.options` field. * @type string $username * Optional username for logging in to a docker registry. If username * matches `projects/*/secrets/*/versions/*` then Batch will read the @@ -257,8 +259,9 @@ public function setOptions($var) /** * If set to true, external network access to and from container will be - * blocked. The container will use the default internal network - * 'goog-internal'. + * blocked, containers that are with block_external_network as true can + * still communicate with each other, network cannot be specified in the + * `container.options` field. * * Generated from protobuf field bool block_external_network = 9; * @return bool @@ -270,8 +273,9 @@ public function getBlockExternalNetwork() /** * If set to true, external network access to and from container will be - * blocked. The container will use the default internal network - * 'goog-internal'. + * blocked, containers that are with block_external_network as true can + * still communicate with each other, network cannot be specified in the + * `container.options` field. * * Generated from protobuf field bool block_external_network = 9; * @param bool $var diff --git a/Batch/src/V1/TaskGroup.php b/Batch/src/V1/TaskGroup.php index 1b46382a853e..6a0a4fe0d0e1 100644 --- a/Batch/src/V1/TaskGroup.php +++ b/Batch/src/V1/TaskGroup.php @@ -33,7 +33,7 @@ class TaskGroup extends \Google\Protobuf\Internal\Message private $task_spec = null; /** * Number of Tasks in the TaskGroup. - * default is 1 + * Default is 1. * * Generated from protobuf field int64 task_count = 4; */ @@ -41,6 +41,7 @@ class TaskGroup extends \Google\Protobuf\Internal\Message /** * Max number of tasks that can run in parallel. * Default to min(task_count, 1000). + * Field parallelism must be 1 if the scheduling_policy is IN_ORDER. * * Generated from protobuf field int64 parallelism = 5; */ @@ -98,10 +99,11 @@ class TaskGroup extends \Google\Protobuf\Internal\Message * Required. Tasks in the group share the same task spec. * @type int|string $task_count * Number of Tasks in the TaskGroup. - * default is 1 + * Default is 1. * @type int|string $parallelism * Max number of tasks that can run in parallel. * Default to min(task_count, 1000). + * Field parallelism must be 1 if the scheduling_policy is IN_ORDER. * @type array<\Google\Cloud\Batch\V1\Environment>|\Google\Protobuf\Internal\RepeatedField $task_environments * An array of environment variable mappings, which are passed to Tasks with * matching indices. If task_environments is used then task_count should @@ -200,7 +202,7 @@ public function setTaskSpec($var) /** * Number of Tasks in the TaskGroup. - * default is 1 + * Default is 1. * * Generated from protobuf field int64 task_count = 4; * @return int|string @@ -212,7 +214,7 @@ public function getTaskCount() /** * Number of Tasks in the TaskGroup. - * default is 1 + * Default is 1. * * Generated from protobuf field int64 task_count = 4; * @param int|string $var @@ -229,6 +231,7 @@ public function setTaskCount($var) /** * Max number of tasks that can run in parallel. * Default to min(task_count, 1000). + * Field parallelism must be 1 if the scheduling_policy is IN_ORDER. * * Generated from protobuf field int64 parallelism = 5; * @return int|string @@ -241,6 +244,7 @@ public function getParallelism() /** * Max number of tasks that can run in parallel. * Default to min(task_count, 1000). + * Field parallelism must be 1 if the scheduling_policy is IN_ORDER. * * Generated from protobuf field int64 parallelism = 5; * @param int|string $var diff --git a/Batch/src/V1/TaskStatus/State.php b/Batch/src/V1/TaskStatus/State.php index 21886ebdb4c9..c19b4875429b 100644 --- a/Batch/src/V1/TaskStatus/State.php +++ b/Batch/src/V1/TaskStatus/State.php @@ -14,7 +14,7 @@ class State { /** - * unknown state + * Unknown state. * * Generated from protobuf enum STATE_UNSPECIFIED = 0; */ @@ -49,6 +49,12 @@ class State * Generated from protobuf enum SUCCEEDED = 5; */ const SUCCEEDED = 5; + /** + * The Task has not been executed when the Job finishes. + * + * Generated from protobuf enum UNEXECUTED = 6; + */ + const UNEXECUTED = 6; private static $valueToName = [ self::STATE_UNSPECIFIED => 'STATE_UNSPECIFIED', @@ -57,6 +63,7 @@ class State self::RUNNING => 'RUNNING', self::FAILED => 'FAILED', self::SUCCEEDED => 'SUCCEEDED', + self::UNEXECUTED => 'UNEXECUTED', ]; public static function name($value) diff --git a/Batch/src/V1/resources/batch_service_descriptor_config.php b/Batch/src/V1/resources/batch_service_descriptor_config.php index febed4cf12e5..3b05da1b865f 100644 --- a/Batch/src/V1/resources/batch_service_descriptor_config.php +++ b/Batch/src/V1/resources/batch_service_descriptor_config.php @@ -12,6 +12,51 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'CreateJob' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Batch\V1\Job', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'GetJob' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Batch\V1\Job', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetTask' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Batch\V1\Task', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'ListJobs' => [ 'pageStreaming' => [ @@ -22,6 +67,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getJobs', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\Batch\V1\ListJobsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ListTasks' => [ 'pageStreaming' => [ @@ -32,8 +87,28 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getTasks', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\Batch\V1\ListTasksResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'GetLocation' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Location\Location', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], 'interfaceOverride' => 'google.cloud.location.Locations', ], 'ListLocations' => [ @@ -45,8 +120,24 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getLocations', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\Location\ListLocationsResponse', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], 'interfaceOverride' => 'google.cloud.location.Locations', ], + 'templateMap' => [ + 'job' => 'projects/{project}/locations/{location}/jobs/{job}', + 'location' => 'projects/{project}/locations/{location}', + 'task' => 'projects/{project}/locations/{location}/jobs/{job}/taskGroups/{task_group}/tasks/{task}', + 'taskGroup' => 'projects/{project}/locations/{location}/jobs/{job}/taskGroups/{task_group}', + ], ], ], ]; diff --git a/Batch/src/V1/resources/batch_service_rest_client_config.php b/Batch/src/V1/resources/batch_service_rest_client_config.php index a72321464b81..9078db01cf28 100644 --- a/Batch/src/V1/resources/batch_service_rest_client_config.php +++ b/Batch/src/V1/resources/batch_service_rest_client_config.php @@ -96,29 +96,6 @@ ], ], 'google.longrunning.Operations' => [ - 'CancelOperation' => [ - 'method' => 'post', - 'uriTemplate' => '/v1/{name=projects/*/locations/*/operations/*}:cancel', - 'body' => '*', - 'placeholders' => [ - 'name' => [ - 'getters' => [ - 'getName', - ], - ], - ], - ], - 'DeleteOperation' => [ - 'method' => 'delete', - 'uriTemplate' => '/v1/{name=projects/*/locations/*/operations/*}', - 'placeholders' => [ - 'name' => [ - 'getters' => [ - 'getName', - ], - ], - ], - ], 'GetOperation' => [ 'method' => 'get', 'uriTemplate' => '/v1/{name=projects/*/locations/*/operations/*}', diff --git a/Batch/tests/Unit/V1/Client/BatchServiceClientTest.php b/Batch/tests/Unit/V1/Client/BatchServiceClientTest.php new file mode 100644 index 000000000000..e89f0ab1331a --- /dev/null +++ b/Batch/tests/Unit/V1/Client/BatchServiceClientTest.php @@ -0,0 +1,701 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return BatchServiceClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new BatchServiceClient($options); + } + + /** @test */ + public function createJobTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $uid = 'uid115792'; + $priority = 1165461084; + $expectedResponse = new Job(); + $expectedResponse->setName($name); + $expectedResponse->setUid($uid); + $expectedResponse->setPriority($priority); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $job = new Job(); + $jobTaskGroups = []; + $job->setTaskGroups($jobTaskGroups); + $request = (new CreateJobRequest()) + ->setParent($formattedParent) + ->setJob($job); + $response = $gapicClient->createJob($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.batch.v1.BatchService/CreateJob', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getJob(); + $this->assertProtobufEquals($job, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createJobExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $job = new Job(); + $jobTaskGroups = []; + $job->setTaskGroups($jobTaskGroups); + $request = (new CreateJobRequest()) + ->setParent($formattedParent) + ->setJob($job); + try { + $gapicClient->createJob($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteJobTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/deleteJobTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new GPBEmpty(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/deleteJobTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + $request = new DeleteJobRequest(); + $response = $gapicClient->deleteJob($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.batch.v1.BatchService/DeleteJob', $actualApiFuncCall); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteJobTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function deleteJobExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/deleteJobTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + $request = new DeleteJobRequest(); + $response = $gapicClient->deleteJob($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteJobTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function getJobTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $uid = 'uid115792'; + $priority = 1165461084; + $expectedResponse = new Job(); + $expectedResponse->setName($name2); + $expectedResponse->setUid($uid); + $expectedResponse->setPriority($priority); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->jobName('[PROJECT]', '[LOCATION]', '[JOB]'); + $request = (new GetJobRequest()) + ->setName($formattedName); + $response = $gapicClient->getJob($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.batch.v1.BatchService/GetJob', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getJobExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->jobName('[PROJECT]', '[LOCATION]', '[JOB]'); + $request = (new GetJobRequest()) + ->setName($formattedName); + try { + $gapicClient->getJob($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getTaskTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $expectedResponse = new Task(); + $expectedResponse->setName($name2); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->taskName('[PROJECT]', '[LOCATION]', '[JOB]', '[TASK_GROUP]', '[TASK]'); + $request = (new GetTaskRequest()) + ->setName($formattedName); + $response = $gapicClient->getTask($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.batch.v1.BatchService/GetTask', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getTaskExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->taskName('[PROJECT]', '[LOCATION]', '[JOB]', '[TASK_GROUP]', '[TASK]'); + $request = (new GetTaskRequest()) + ->setName($formattedName); + try { + $gapicClient->getTask($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listJobsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $jobsElement = new Job(); + $jobs = [ + $jobsElement, + ]; + $expectedResponse = new ListJobsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setJobs($jobs); + $transport->addResponse($expectedResponse); + $request = new ListJobsRequest(); + $response = $gapicClient->listJobs($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getJobs()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.batch.v1.BatchService/ListJobs', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listJobsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + $request = new ListJobsRequest(); + try { + $gapicClient->listJobs($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listTasksTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $tasksElement = new Task(); + $tasks = [ + $tasksElement, + ]; + $expectedResponse = new ListTasksResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setTasks($tasks); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->taskGroupName('[PROJECT]', '[LOCATION]', '[JOB]', '[TASK_GROUP]'); + $request = (new ListTasksRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listTasks($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getTasks()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.batch.v1.BatchService/ListTasks', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listTasksExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->taskGroupName('[PROJECT]', '[LOCATION]', '[JOB]', '[TASK_GROUP]'); + $request = (new ListTasksRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listTasks($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getLocationTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $locationId = 'locationId552319461'; + $displayName = 'displayName1615086568'; + $expectedResponse = new Location(); + $expectedResponse->setName($name2); + $expectedResponse->setLocationId($locationId); + $expectedResponse->setDisplayName($displayName); + $transport->addResponse($expectedResponse); + $request = new GetLocationRequest(); + $response = $gapicClient->getLocation($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.location.Locations/GetLocation', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getLocationExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + $request = new GetLocationRequest(); + try { + $gapicClient->getLocation($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listLocationsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $locationsElement = new Location(); + $locations = [ + $locationsElement, + ]; + $expectedResponse = new ListLocationsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setLocations($locations); + $transport->addResponse($expectedResponse); + $request = new ListLocationsRequest(); + $response = $gapicClient->listLocations($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getLocations()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.location.Locations/ListLocations', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listLocationsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + $request = new ListLocationsRequest(); + try { + $gapicClient->listLocations($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createJobAsyncTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $uid = 'uid115792'; + $priority = 1165461084; + $expectedResponse = new Job(); + $expectedResponse->setName($name); + $expectedResponse->setUid($uid); + $expectedResponse->setPriority($priority); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $job = new Job(); + $jobTaskGroups = []; + $job->setTaskGroups($jobTaskGroups); + $request = (new CreateJobRequest()) + ->setParent($formattedParent) + ->setJob($job); + $response = $gapicClient->createJobAsync($request)->wait(); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.batch.v1.BatchService/CreateJob', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getJob(); + $this->assertProtobufEquals($job, $actualValue); + $this->assertTrue($transport->isExhausted()); + } +} diff --git a/BeyondCorpAppConnections/samples/V1/AppConnectionsServiceClient/create_app_connection.php b/BeyondCorpAppConnections/samples/V1/AppConnectionsServiceClient/create_app_connection.php index ebee98608822..221fd47b0158 100644 --- a/BeyondCorpAppConnections/samples/V1/AppConnectionsServiceClient/create_app_connection.php +++ b/BeyondCorpAppConnections/samples/V1/AppConnectionsServiceClient/create_app_connection.php @@ -28,7 +28,8 @@ use Google\Cloud\BeyondCorp\AppConnections\V1\AppConnection; use Google\Cloud\BeyondCorp\AppConnections\V1\AppConnection\ApplicationEndpoint; use Google\Cloud\BeyondCorp\AppConnections\V1\AppConnection\Type; -use Google\Cloud\BeyondCorp\AppConnections\V1\AppConnectionsServiceClient; +use Google\Cloud\BeyondCorp\AppConnections\V1\Client\AppConnectionsServiceClient; +use Google\Cloud\BeyondCorp\AppConnections\V1\CreateAppConnectionRequest; use Google\Rpc\Status; /** @@ -53,7 +54,7 @@ function create_app_connection_sample( // Create a client. $appConnectionsServiceClient = new AppConnectionsServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $appConnectionApplicationEndpoint = (new ApplicationEndpoint()) ->setHost($appConnectionApplicationEndpointHost) ->setPort($appConnectionApplicationEndpointPort); @@ -61,11 +62,14 @@ function create_app_connection_sample( ->setName($appConnectionName) ->setType($appConnectionType) ->setApplicationEndpoint($appConnectionApplicationEndpoint); + $request = (new CreateAppConnectionRequest()) + ->setParent($formattedParent) + ->setAppConnection($appConnection); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $appConnectionsServiceClient->createAppConnection($formattedParent, $appConnection); + $response = $appConnectionsServiceClient->createAppConnection($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/BeyondCorpAppConnections/samples/V1/AppConnectionsServiceClient/delete_app_connection.php b/BeyondCorpAppConnections/samples/V1/AppConnectionsServiceClient/delete_app_connection.php index b0a9d5f7b4b7..402dcc877cdf 100644 --- a/BeyondCorpAppConnections/samples/V1/AppConnectionsServiceClient/delete_app_connection.php +++ b/BeyondCorpAppConnections/samples/V1/AppConnectionsServiceClient/delete_app_connection.php @@ -25,7 +25,8 @@ // [START beyondcorp_v1_generated_AppConnectionsService_DeleteAppConnection_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\BeyondCorp\AppConnections\V1\AppConnectionsServiceClient; +use Google\Cloud\BeyondCorp\AppConnections\V1\Client\AppConnectionsServiceClient; +use Google\Cloud\BeyondCorp\AppConnections\V1\DeleteAppConnectionRequest; use Google\Rpc\Status; /** @@ -40,10 +41,14 @@ function delete_app_connection_sample(string $formattedName): void // Create a client. $appConnectionsServiceClient = new AppConnectionsServiceClient(); + // Prepare the request message. + $request = (new DeleteAppConnectionRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $appConnectionsServiceClient->deleteAppConnection($formattedName); + $response = $appConnectionsServiceClient->deleteAppConnection($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/BeyondCorpAppConnections/samples/V1/AppConnectionsServiceClient/get_app_connection.php b/BeyondCorpAppConnections/samples/V1/AppConnectionsServiceClient/get_app_connection.php index 741db00d3f13..c5aa488fb4bc 100644 --- a/BeyondCorpAppConnections/samples/V1/AppConnectionsServiceClient/get_app_connection.php +++ b/BeyondCorpAppConnections/samples/V1/AppConnectionsServiceClient/get_app_connection.php @@ -25,7 +25,8 @@ // [START beyondcorp_v1_generated_AppConnectionsService_GetAppConnection_sync] use Google\ApiCore\ApiException; use Google\Cloud\BeyondCorp\AppConnections\V1\AppConnection; -use Google\Cloud\BeyondCorp\AppConnections\V1\AppConnectionsServiceClient; +use Google\Cloud\BeyondCorp\AppConnections\V1\Client\AppConnectionsServiceClient; +use Google\Cloud\BeyondCorp\AppConnections\V1\GetAppConnectionRequest; /** * Gets details of a single AppConnection. @@ -39,10 +40,14 @@ function get_app_connection_sample(string $formattedName): void // Create a client. $appConnectionsServiceClient = new AppConnectionsServiceClient(); + // Prepare the request message. + $request = (new GetAppConnectionRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var AppConnection $response */ - $response = $appConnectionsServiceClient->getAppConnection($formattedName); + $response = $appConnectionsServiceClient->getAppConnection($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BeyondCorpAppConnections/samples/V1/AppConnectionsServiceClient/get_iam_policy.php b/BeyondCorpAppConnections/samples/V1/AppConnectionsServiceClient/get_iam_policy.php index 4b9a5609e5d9..4e638a5cd999 100644 --- a/BeyondCorpAppConnections/samples/V1/AppConnectionsServiceClient/get_iam_policy.php +++ b/BeyondCorpAppConnections/samples/V1/AppConnectionsServiceClient/get_iam_policy.php @@ -24,7 +24,8 @@ // [START beyondcorp_v1_generated_AppConnectionsService_GetIamPolicy_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BeyondCorp\AppConnections\V1\AppConnectionsServiceClient; +use Google\Cloud\BeyondCorp\AppConnections\V1\Client\AppConnectionsServiceClient; +use Google\Cloud\Iam\V1\GetIamPolicyRequest; use Google\Cloud\Iam\V1\Policy; /** @@ -39,10 +40,14 @@ function get_iam_policy_sample(string $resource): void // Create a client. $appConnectionsServiceClient = new AppConnectionsServiceClient(); + // Prepare the request message. + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + // Call the API and handle any network failures. try { /** @var Policy $response */ - $response = $appConnectionsServiceClient->getIamPolicy($resource); + $response = $appConnectionsServiceClient->getIamPolicy($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BeyondCorpAppConnections/samples/V1/AppConnectionsServiceClient/get_location.php b/BeyondCorpAppConnections/samples/V1/AppConnectionsServiceClient/get_location.php index c8dba622fa3e..dbf101df5735 100644 --- a/BeyondCorpAppConnections/samples/V1/AppConnectionsServiceClient/get_location.php +++ b/BeyondCorpAppConnections/samples/V1/AppConnectionsServiceClient/get_location.php @@ -24,7 +24,8 @@ // [START beyondcorp_v1_generated_AppConnectionsService_GetLocation_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BeyondCorp\AppConnections\V1\AppConnectionsServiceClient; +use Google\Cloud\BeyondCorp\AppConnections\V1\Client\AppConnectionsServiceClient; +use Google\Cloud\Location\GetLocationRequest; use Google\Cloud\Location\Location; /** @@ -41,10 +42,13 @@ function get_location_sample(): void // Create a client. $appConnectionsServiceClient = new AppConnectionsServiceClient(); + // Prepare the request message. + $request = new GetLocationRequest(); + // Call the API and handle any network failures. try { /** @var Location $response */ - $response = $appConnectionsServiceClient->getLocation(); + $response = $appConnectionsServiceClient->getLocation($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BeyondCorpAppConnections/samples/V1/AppConnectionsServiceClient/list_app_connections.php b/BeyondCorpAppConnections/samples/V1/AppConnectionsServiceClient/list_app_connections.php index fa81da9dc6e7..b82bce085b23 100644 --- a/BeyondCorpAppConnections/samples/V1/AppConnectionsServiceClient/list_app_connections.php +++ b/BeyondCorpAppConnections/samples/V1/AppConnectionsServiceClient/list_app_connections.php @@ -26,7 +26,8 @@ use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; use Google\Cloud\BeyondCorp\AppConnections\V1\AppConnection; -use Google\Cloud\BeyondCorp\AppConnections\V1\AppConnectionsServiceClient; +use Google\Cloud\BeyondCorp\AppConnections\V1\Client\AppConnectionsServiceClient; +use Google\Cloud\BeyondCorp\AppConnections\V1\ListAppConnectionsRequest; /** * Lists AppConnections in a given project and location. @@ -40,10 +41,14 @@ function list_app_connections_sample(string $formattedParent): void // Create a client. $appConnectionsServiceClient = new AppConnectionsServiceClient(); + // Prepare the request message. + $request = (new ListAppConnectionsRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $appConnectionsServiceClient->listAppConnections($formattedParent); + $response = $appConnectionsServiceClient->listAppConnections($request); /** @var AppConnection $element */ foreach ($response as $element) { diff --git a/BeyondCorpAppConnections/samples/V1/AppConnectionsServiceClient/list_locations.php b/BeyondCorpAppConnections/samples/V1/AppConnectionsServiceClient/list_locations.php index d0b379f37def..b56ae1c1958f 100644 --- a/BeyondCorpAppConnections/samples/V1/AppConnectionsServiceClient/list_locations.php +++ b/BeyondCorpAppConnections/samples/V1/AppConnectionsServiceClient/list_locations.php @@ -25,7 +25,8 @@ // [START beyondcorp_v1_generated_AppConnectionsService_ListLocations_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; -use Google\Cloud\BeyondCorp\AppConnections\V1\AppConnectionsServiceClient; +use Google\Cloud\BeyondCorp\AppConnections\V1\Client\AppConnectionsServiceClient; +use Google\Cloud\Location\ListLocationsRequest; use Google\Cloud\Location\Location; /** @@ -42,10 +43,13 @@ function list_locations_sample(): void // Create a client. $appConnectionsServiceClient = new AppConnectionsServiceClient(); + // Prepare the request message. + $request = new ListLocationsRequest(); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $appConnectionsServiceClient->listLocations(); + $response = $appConnectionsServiceClient->listLocations($request); /** @var Location $element */ foreach ($response as $element) { diff --git a/BeyondCorpAppConnections/samples/V1/AppConnectionsServiceClient/resolve_app_connections.php b/BeyondCorpAppConnections/samples/V1/AppConnectionsServiceClient/resolve_app_connections.php index 21a8ba6b2d9c..dc13d13543ea 100644 --- a/BeyondCorpAppConnections/samples/V1/AppConnectionsServiceClient/resolve_app_connections.php +++ b/BeyondCorpAppConnections/samples/V1/AppConnectionsServiceClient/resolve_app_connections.php @@ -25,7 +25,8 @@ // [START beyondcorp_v1_generated_AppConnectionsService_ResolveAppConnections_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; -use Google\Cloud\BeyondCorp\AppConnections\V1\AppConnectionsServiceClient; +use Google\Cloud\BeyondCorp\AppConnections\V1\Client\AppConnectionsServiceClient; +use Google\Cloud\BeyondCorp\AppConnections\V1\ResolveAppConnectionsRequest; use Google\Cloud\BeyondCorp\AppConnections\V1\ResolveAppConnectionsResponse\AppConnectionDetails; /** @@ -48,13 +49,15 @@ function resolve_app_connections_sample( // Create a client. $appConnectionsServiceClient = new AppConnectionsServiceClient(); + // Prepare the request message. + $request = (new ResolveAppConnectionsRequest()) + ->setParent($formattedParent) + ->setAppConnectorId($formattedAppConnectorId); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $appConnectionsServiceClient->resolveAppConnections( - $formattedParent, - $formattedAppConnectorId - ); + $response = $appConnectionsServiceClient->resolveAppConnections($request); /** @var AppConnectionDetails $element */ foreach ($response as $element) { diff --git a/BeyondCorpAppConnections/samples/V1/AppConnectionsServiceClient/set_iam_policy.php b/BeyondCorpAppConnections/samples/V1/AppConnectionsServiceClient/set_iam_policy.php index 444d0b5ebc2e..c7939e0824b2 100644 --- a/BeyondCorpAppConnections/samples/V1/AppConnectionsServiceClient/set_iam_policy.php +++ b/BeyondCorpAppConnections/samples/V1/AppConnectionsServiceClient/set_iam_policy.php @@ -24,8 +24,9 @@ // [START beyondcorp_v1_generated_AppConnectionsService_SetIamPolicy_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BeyondCorp\AppConnections\V1\AppConnectionsServiceClient; +use Google\Cloud\BeyondCorp\AppConnections\V1\Client\AppConnectionsServiceClient; use Google\Cloud\Iam\V1\Policy; +use Google\Cloud\Iam\V1\SetIamPolicyRequest; /** * Sets the access control policy on the specified resource. Replaces @@ -42,13 +43,16 @@ function set_iam_policy_sample(string $resource): void // Create a client. $appConnectionsServiceClient = new AppConnectionsServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $policy = new Policy(); + $request = (new SetIamPolicyRequest()) + ->setResource($resource) + ->setPolicy($policy); // Call the API and handle any network failures. try { /** @var Policy $response */ - $response = $appConnectionsServiceClient->setIamPolicy($resource, $policy); + $response = $appConnectionsServiceClient->setIamPolicy($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BeyondCorpAppConnections/samples/V1/AppConnectionsServiceClient/test_iam_permissions.php b/BeyondCorpAppConnections/samples/V1/AppConnectionsServiceClient/test_iam_permissions.php index 6b41cf032e2a..a700f9fe57fd 100644 --- a/BeyondCorpAppConnections/samples/V1/AppConnectionsServiceClient/test_iam_permissions.php +++ b/BeyondCorpAppConnections/samples/V1/AppConnectionsServiceClient/test_iam_permissions.php @@ -24,7 +24,8 @@ // [START beyondcorp_v1_generated_AppConnectionsService_TestIamPermissions_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BeyondCorp\AppConnections\V1\AppConnectionsServiceClient; +use Google\Cloud\BeyondCorp\AppConnections\V1\Client\AppConnectionsServiceClient; +use Google\Cloud\Iam\V1\TestIamPermissionsRequest; use Google\Cloud\Iam\V1\TestIamPermissionsResponse; /** @@ -48,13 +49,16 @@ function test_iam_permissions_sample(string $resource, string $permissionsElemen // Create a client. $appConnectionsServiceClient = new AppConnectionsServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $permissions = [$permissionsElement,]; + $request = (new TestIamPermissionsRequest()) + ->setResource($resource) + ->setPermissions($permissions); // Call the API and handle any network failures. try { /** @var TestIamPermissionsResponse $response */ - $response = $appConnectionsServiceClient->testIamPermissions($resource, $permissions); + $response = $appConnectionsServiceClient->testIamPermissions($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BeyondCorpAppConnections/samples/V1/AppConnectionsServiceClient/update_app_connection.php b/BeyondCorpAppConnections/samples/V1/AppConnectionsServiceClient/update_app_connection.php index adf18d4e77cf..98bf10f2dd9b 100644 --- a/BeyondCorpAppConnections/samples/V1/AppConnectionsServiceClient/update_app_connection.php +++ b/BeyondCorpAppConnections/samples/V1/AppConnectionsServiceClient/update_app_connection.php @@ -28,7 +28,8 @@ use Google\Cloud\BeyondCorp\AppConnections\V1\AppConnection; use Google\Cloud\BeyondCorp\AppConnections\V1\AppConnection\ApplicationEndpoint; use Google\Cloud\BeyondCorp\AppConnections\V1\AppConnection\Type; -use Google\Cloud\BeyondCorp\AppConnections\V1\AppConnectionsServiceClient; +use Google\Cloud\BeyondCorp\AppConnections\V1\Client\AppConnectionsServiceClient; +use Google\Cloud\BeyondCorp\AppConnections\V1\UpdateAppConnectionRequest; use Google\Protobuf\FieldMask; use Google\Rpc\Status; @@ -50,7 +51,7 @@ function update_app_connection_sample( // Create a client. $appConnectionsServiceClient = new AppConnectionsServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $updateMask = new FieldMask(); $appConnectionApplicationEndpoint = (new ApplicationEndpoint()) ->setHost($appConnectionApplicationEndpointHost) @@ -59,11 +60,14 @@ function update_app_connection_sample( ->setName($appConnectionName) ->setType($appConnectionType) ->setApplicationEndpoint($appConnectionApplicationEndpoint); + $request = (new UpdateAppConnectionRequest()) + ->setUpdateMask($updateMask) + ->setAppConnection($appConnection); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $appConnectionsServiceClient->updateAppConnection($updateMask, $appConnection); + $response = $appConnectionsServiceClient->updateAppConnection($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/BeyondCorpAppConnections/src/V1/Client/AppConnectionsServiceClient.php b/BeyondCorpAppConnections/src/V1/Client/AppConnectionsServiceClient.php new file mode 100644 index 000000000000..b42b2bf42386 --- /dev/null +++ b/BeyondCorpAppConnections/src/V1/Client/AppConnectionsServiceClient.php @@ -0,0 +1,40 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/app_connections_service_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/app_connections_service_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/app_connections_service_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/app_connections_service_rest_client_config.php', + ], + ], + ]; + } + + /** + * Return an OperationsClient object with the same endpoint as $this. + * + * @return OperationsClient + */ + public function getOperationsClient() + { + return $this->operationsClient; + } + + /** + * Resume an existing long running operation that was previously started by a long + * running API method. If $methodName is not provided, or does not match a long + * running API method, then the operation can still be resumed, but the + * OperationResponse object will not deserialize the final response. + * + * @param string $operationName The name of the long running operation + * @param string $methodName The name of the method used to start the operation + * + * @return OperationResponse + */ + public function resumeOperation($operationName, $methodName = null) + { + $options = isset($this->descriptors[$methodName]['longRunning']) ? $this->descriptors[$methodName]['longRunning'] : []; + $operation = new OperationResponse($operationName, $this->getOperationsClient(), $options); + $operation->reload(); + return $operation; + } + + /** + * Formats a string containing the fully-qualified path to represent a + * app_connection resource. + * + * @param string $project + * @param string $location + * @param string $appConnection + * + * @return string The formatted app_connection resource. + */ + public static function appConnectionName(string $project, string $location, string $appConnection): string + { + return self::getPathTemplate('appConnection')->render([ + 'project' => $project, + 'location' => $location, + 'app_connection' => $appConnection, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a + * app_connector resource. + * + * @param string $project + * @param string $location + * @param string $appConnector + * + * @return string The formatted app_connector resource. + */ + public static function appConnectorName(string $project, string $location, string $appConnector): string + { + return self::getPathTemplate('appConnector')->render([ + 'project' => $project, + 'location' => $location, + 'app_connector' => $appConnector, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a app_gateway + * resource. + * + * @param string $project + * @param string $location + * @param string $appGateway + * + * @return string The formatted app_gateway resource. + */ + public static function appGatewayName(string $project, string $location, string $appGateway): string + { + return self::getPathTemplate('appGateway')->render([ + 'project' => $project, + 'location' => $location, + 'app_gateway' => $appGateway, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a location + * resource. + * + * @param string $project + * @param string $location + * + * @return string The formatted location resource. + */ + public static function locationName(string $project, string $location): string + { + return self::getPathTemplate('location')->render([ + 'project' => $project, + 'location' => $location, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * Template: Pattern + * - appConnection: projects/{project}/locations/{location}/appConnections/{app_connection} + * - appConnector: projects/{project}/locations/{location}/appConnectors/{app_connector} + * - appGateway: projects/{project}/locations/{location}/appGateways/{app_gateway} + * - location: projects/{project}/locations/{location} + * + * The optional $template argument can be supplied to specify a particular pattern, + * and must match one of the templates listed above. If no $template argument is + * provided, or if the $template argument does not match one of the templates + * listed, then parseName will check each of the supported templates, and return + * the first match. + * + * @param string $formattedName The formatted name string + * @param string $template Optional name of template to match + * + * @return array An associative array from name component IDs to component values. + * + * @throws ValidationException If $formattedName could not be matched. + */ + public static function parseName(string $formattedName, string $template = null): array + { + return self::parseFormattedName($formattedName, $template); + } + + /** + * Constructor. + * + * @param array $options { + * Optional. Options for configuring the service API wrapper. + * + * @type string $apiEndpoint + * The address of the API remote host. May optionally include the port, formatted + * as ":". Default 'beyondcorp.googleapis.com:443'. + * @type string|array|FetchAuthTokenInterface|CredentialsWrapper $credentials + * The credentials to be used by the client to authorize API calls. This option + * accepts either a path to a credentials file, or a decoded credentials file as a + * PHP array. + * *Advanced usage*: In addition, this option can also accept a pre-constructed + * {@see \Google\Auth\FetchAuthTokenInterface} object or + * {@see \Google\ApiCore\CredentialsWrapper} object. Note that when one of these + * objects are provided, any settings in $credentialsConfig will be ignored. + * @type array $credentialsConfig + * Options used to configure credentials, including auth token caching, for the + * client. For a full list of supporting configuration options, see + * {@see \Google\ApiCore\CredentialsWrapper::build()} . + * @type bool $disableRetries + * Determines whether or not retries defined by the client configuration should be + * disabled. Defaults to `false`. + * @type string|array $clientConfig + * Client method configuration, including retry settings. This option can be either + * a path to a JSON file, or a PHP array containing the decoded JSON data. By + * default this settings points to the default client config file, which is + * provided in the resources folder. + * @type string|TransportInterface $transport + * The transport used for executing network requests. May be either the string + * `rest` or `grpc`. Defaults to `grpc` if gRPC support is detected on the system. + * *Advanced usage*: Additionally, it is possible to pass in an already + * instantiated {@see \Google\ApiCore\Transport\TransportInterface} object. Note + * that when this object is provided, any settings in $transportConfig, and any + * $apiEndpoint setting, will be ignored. + * @type array $transportConfig + * Configuration options that will be used to construct the transport. Options for + * each supported transport type should be passed in a key for that transport. For + * example: + * $transportConfig = [ + * 'grpc' => [...], + * 'rest' => [...], + * ]; + * See the {@see \Google\ApiCore\Transport\GrpcTransport::build()} and + * {@see \Google\ApiCore\Transport\RestTransport::build()} methods for the + * supported options. + * @type callable $clientCertSource + * A callable which returns the client cert as a string. This can be used to + * provide a certificate and private key to the transport layer for mTLS. + * } + * + * @throws ValidationException + */ + public function __construct(array $options = []) + { + $clientOptions = $this->buildClientOptions($options); + $this->setClientOptions($clientOptions); + $this->operationsClient = $this->createOperationsClient($clientOptions); + } + + /** Handles execution of the async variants for each documented method. */ + public function __call($method, $args) + { + if (substr($method, -5) !== 'Async') { + trigger_error('Call to undefined method ' . __CLASS__ . "::$method()", E_USER_ERROR); + } + + array_unshift($args, substr($method, 0, -5)); + return call_user_func_array([$this, 'startAsyncCall'], $args); + } + + /** + * Creates a new AppConnection in a given project and location. + * + * The async variant is {@see self::createAppConnectionAsync()} . + * + * @param CreateAppConnectionRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function createAppConnection(CreateAppConnectionRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('CreateAppConnection', $request, $callOptions)->wait(); + } + + /** + * Deletes a single AppConnection. + * + * The async variant is {@see self::deleteAppConnectionAsync()} . + * + * @param DeleteAppConnectionRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function deleteAppConnection(DeleteAppConnectionRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('DeleteAppConnection', $request, $callOptions)->wait(); + } + + /** + * Gets details of a single AppConnection. + * + * The async variant is {@see self::getAppConnectionAsync()} . + * + * @param GetAppConnectionRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return AppConnection + * + * @throws ApiException Thrown if the API call fails. + */ + public function getAppConnection(GetAppConnectionRequest $request, array $callOptions = []): AppConnection + { + return $this->startApiCall('GetAppConnection', $request, $callOptions)->wait(); + } + + /** + * Lists AppConnections in a given project and location. + * + * The async variant is {@see self::listAppConnectionsAsync()} . + * + * @param ListAppConnectionsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listAppConnections(ListAppConnectionsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListAppConnections', $request, $callOptions); + } + + /** + * Resolves AppConnections details for a given AppConnector. + * An internal method called by a connector to find AppConnections to connect + * to. + * + * The async variant is {@see self::resolveAppConnectionsAsync()} . + * + * @param ResolveAppConnectionsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function resolveAppConnections(ResolveAppConnectionsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ResolveAppConnections', $request, $callOptions); + } + + /** + * Updates the parameters of a single AppConnection. + * + * The async variant is {@see self::updateAppConnectionAsync()} . + * + * @param UpdateAppConnectionRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function updateAppConnection(UpdateAppConnectionRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('UpdateAppConnection', $request, $callOptions)->wait(); + } + + /** + * Gets information about a location. + * + * The async variant is {@see self::getLocationAsync()} . + * + * @param GetLocationRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Location + * + * @throws ApiException Thrown if the API call fails. + */ + public function getLocation(GetLocationRequest $request, array $callOptions = []): Location + { + return $this->startApiCall('GetLocation', $request, $callOptions)->wait(); + } + + /** + * Lists information about the supported locations for this service. + * + * The async variant is {@see self::listLocationsAsync()} . + * + * @param ListLocationsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listLocations(ListLocationsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListLocations', $request, $callOptions); + } + + /** + * Gets the access control policy for a resource. Returns an empty policy + if the resource exists and does not have a policy set. + * + * The async variant is {@see self::getIamPolicyAsync()} . + * + * @param GetIamPolicyRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Policy + * + * @throws ApiException Thrown if the API call fails. + */ + public function getIamPolicy(GetIamPolicyRequest $request, array $callOptions = []): Policy + { + return $this->startApiCall('GetIamPolicy', $request, $callOptions)->wait(); + } + + /** + * Sets the access control policy on the specified resource. Replaces + any existing policy. + + Can return `NOT_FOUND`, `INVALID_ARGUMENT`, and `PERMISSION_DENIED` + errors. + * + * The async variant is {@see self::setIamPolicyAsync()} . + * + * @param SetIamPolicyRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Policy + * + * @throws ApiException Thrown if the API call fails. + */ + public function setIamPolicy(SetIamPolicyRequest $request, array $callOptions = []): Policy + { + return $this->startApiCall('SetIamPolicy', $request, $callOptions)->wait(); + } + + /** + * Returns permissions that a caller has on the specified resource. If the + resource does not exist, this will return an empty set of + permissions, not a `NOT_FOUND` error. + + Note: This operation is designed to be used for building + permission-aware UIs and command-line tools, not for authorization + checking. This operation may "fail open" without warning. + * + * The async variant is {@see self::testIamPermissionsAsync()} . + * + * @param TestIamPermissionsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return TestIamPermissionsResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function testIamPermissions(TestIamPermissionsRequest $request, array $callOptions = []): TestIamPermissionsResponse + { + return $this->startApiCall('TestIamPermissions', $request, $callOptions)->wait(); + } +} diff --git a/BeyondCorpAppConnections/src/V1/CreateAppConnectionRequest.php b/BeyondCorpAppConnections/src/V1/CreateAppConnectionRequest.php index 324ed4a9dde1..64e7b7c1e32a 100644 --- a/BeyondCorpAppConnections/src/V1/CreateAppConnectionRequest.php +++ b/BeyondCorpAppConnections/src/V1/CreateAppConnectionRequest.php @@ -61,6 +61,28 @@ class CreateAppConnectionRequest extends \Google\Protobuf\Internal\Message */ private $validate_only = false; + /** + * @param string $parent Required. The resource project name of the AppConnection location using the + * form: `projects/{project_id}/locations/{location_id}` + * Please see {@see AppConnectionsServiceClient::locationName()} for help formatting this field. + * @param \Google\Cloud\BeyondCorp\AppConnections\V1\AppConnection $appConnection Required. A BeyondCorp AppConnection resource. + * @param string $appConnectionId Optional. User-settable AppConnection resource ID. + * * Must start with a letter. + * * Must contain between 4-63 characters from `/[a-z][0-9]-/`. + * * Must end with a number or a letter. + * + * @return \Google\Cloud\BeyondCorp\AppConnections\V1\CreateAppConnectionRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\BeyondCorp\AppConnections\V1\AppConnection $appConnection, string $appConnectionId): self + { + return (new self()) + ->setParent($parent) + ->setAppConnection($appConnection) + ->setAppConnectionId($appConnectionId); + } + /** * Constructor. * diff --git a/BeyondCorpAppConnections/src/V1/DeleteAppConnectionRequest.php b/BeyondCorpAppConnections/src/V1/DeleteAppConnectionRequest.php index 53968baa6866..c32214d2bd1c 100644 --- a/BeyondCorpAppConnections/src/V1/DeleteAppConnectionRequest.php +++ b/BeyondCorpAppConnections/src/V1/DeleteAppConnectionRequest.php @@ -46,6 +46,21 @@ class DeleteAppConnectionRequest extends \Google\Protobuf\Internal\Message */ private $validate_only = false; + /** + * @param string $name Required. BeyondCorp Connector name using the form: + * `projects/{project_id}/locations/{location_id}/appConnections/{app_connection_id}` + * Please see {@see AppConnectionsServiceClient::appConnectionName()} for help formatting this field. + * + * @return \Google\Cloud\BeyondCorp\AppConnections\V1\DeleteAppConnectionRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/BeyondCorpAppConnections/src/V1/GetAppConnectionRequest.php b/BeyondCorpAppConnections/src/V1/GetAppConnectionRequest.php index 9cddaa58b7a5..10bc77a1d4f1 100644 --- a/BeyondCorpAppConnections/src/V1/GetAppConnectionRequest.php +++ b/BeyondCorpAppConnections/src/V1/GetAppConnectionRequest.php @@ -23,6 +23,21 @@ class GetAppConnectionRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. BeyondCorp AppConnection name using the form: + * `projects/{project_id}/locations/{location_id}/appConnections/{app_connection_id}` + * Please see {@see AppConnectionsServiceClient::appConnectionName()} for help formatting this field. + * + * @return \Google\Cloud\BeyondCorp\AppConnections\V1\GetAppConnectionRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/BeyondCorpAppConnections/src/V1/ListAppConnectionsRequest.php b/BeyondCorpAppConnections/src/V1/ListAppConnectionsRequest.php index 0a8b6c8afd4d..ba67e6ebfd44 100644 --- a/BeyondCorpAppConnections/src/V1/ListAppConnectionsRequest.php +++ b/BeyondCorpAppConnections/src/V1/ListAppConnectionsRequest.php @@ -56,6 +56,21 @@ class ListAppConnectionsRequest extends \Google\Protobuf\Internal\Message */ private $order_by = ''; + /** + * @param string $parent Required. The resource name of the AppConnection location using the form: + * `projects/{project_id}/locations/{location_id}` + * Please see {@see AppConnectionsServiceClient::locationName()} for help formatting this field. + * + * @return \Google\Cloud\BeyondCorp\AppConnections\V1\ListAppConnectionsRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/BeyondCorpAppConnections/src/V1/ResolveAppConnectionsRequest.php b/BeyondCorpAppConnections/src/V1/ResolveAppConnectionsRequest.php index 41ad987df0c1..ab361cca1d91 100644 --- a/BeyondCorpAppConnections/src/V1/ResolveAppConnectionsRequest.php +++ b/BeyondCorpAppConnections/src/V1/ResolveAppConnectionsRequest.php @@ -49,6 +49,21 @@ class ResolveAppConnectionsRequest extends \Google\Protobuf\Internal\Message */ private $page_token = ''; + /** + * @param string $parent Required. The resource name of the AppConnection location using the form: + * `projects/{project_id}/locations/{location_id}` + * Please see {@see AppConnectionsServiceClient::locationName()} for help formatting this field. + * + * @return \Google\Cloud\BeyondCorp\AppConnections\V1\ResolveAppConnectionsRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/BeyondCorpAppConnections/src/V1/UpdateAppConnectionRequest.php b/BeyondCorpAppConnections/src/V1/UpdateAppConnectionRequest.php index eb410fb636d9..05617d25054f 100644 --- a/BeyondCorpAppConnections/src/V1/UpdateAppConnectionRequest.php +++ b/BeyondCorpAppConnections/src/V1/UpdateAppConnectionRequest.php @@ -64,6 +64,28 @@ class UpdateAppConnectionRequest extends \Google\Protobuf\Internal\Message */ private $allow_missing = false; + /** + * @param \Google\Cloud\BeyondCorp\AppConnections\V1\AppConnection $appConnection Required. AppConnection message with updated fields. Only supported fields + * specified in update_mask are updated. + * @param \Google\Protobuf\FieldMask $updateMask Required. Mask of fields to update. At least one path must be supplied in + * this field. The elements of the repeated paths field may only include these + * fields from [BeyondCorp.AppConnection]: + * * `labels` + * * `display_name` + * * `application_endpoint` + * * `connectors` + * + * @return \Google\Cloud\BeyondCorp\AppConnections\V1\UpdateAppConnectionRequest + * + * @experimental + */ + public static function build(\Google\Cloud\BeyondCorp\AppConnections\V1\AppConnection $appConnection, \Google\Protobuf\FieldMask $updateMask): self + { + return (new self()) + ->setAppConnection($appConnection) + ->setUpdateMask($updateMask); + } + /** * Constructor. * diff --git a/BeyondCorpAppConnections/src/V1/resources/app_connections_service_descriptor_config.php b/BeyondCorpAppConnections/src/V1/resources/app_connections_service_descriptor_config.php index 4ec11ddc9ef5..0efddabe3d31 100644 --- a/BeyondCorpAppConnections/src/V1/resources/app_connections_service_descriptor_config.php +++ b/BeyondCorpAppConnections/src/V1/resources/app_connections_service_descriptor_config.php @@ -12,6 +12,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'DeleteAppConnection' => [ 'longRunning' => [ @@ -22,6 +31,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'UpdateAppConnection' => [ 'longRunning' => [ @@ -32,6 +50,28 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'app_connection.name', + 'fieldAccessors' => [ + 'getAppConnection', + 'getName', + ], + ], + ], + ], + 'GetAppConnection' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\BeyondCorp\AppConnections\V1\AppConnection', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'ListAppConnections' => [ 'pageStreaming' => [ @@ -42,6 +82,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getAppConnections', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\BeyondCorp\AppConnections\V1\ListAppConnectionsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ResolveAppConnections' => [ 'pageStreaming' => [ @@ -52,8 +102,28 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getAppConnectionDetails', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\BeyondCorp\AppConnections\V1\ResolveAppConnectionsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'GetLocation' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Location\Location', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], 'interfaceOverride' => 'google.cloud.location.Locations', ], 'ListLocations' => [ @@ -65,17 +135,63 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getLocations', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\Location\ListLocationsResponse', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], 'interfaceOverride' => 'google.cloud.location.Locations', ], 'GetIamPolicy' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\Policy', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], 'interfaceOverride' => 'google.iam.v1.IAMPolicy', ], 'SetIamPolicy' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\Policy', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], 'interfaceOverride' => 'google.iam.v1.IAMPolicy', ], 'TestIamPermissions' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\TestIamPermissionsResponse', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], 'interfaceOverride' => 'google.iam.v1.IAMPolicy', ], + 'templateMap' => [ + 'appConnection' => 'projects/{project}/locations/{location}/appConnections/{app_connection}', + 'appConnector' => 'projects/{project}/locations/{location}/appConnectors/{app_connector}', + 'appGateway' => 'projects/{project}/locations/{location}/appGateways/{app_gateway}', + 'location' => 'projects/{project}/locations/{location}', + ], ], ], ]; diff --git a/BeyondCorpAppConnections/tests/Unit/V1/Client/AppConnectionsServiceClientTest.php b/BeyondCorpAppConnections/tests/Unit/V1/Client/AppConnectionsServiceClientTest.php new file mode 100644 index 000000000000..a179a5352807 --- /dev/null +++ b/BeyondCorpAppConnections/tests/Unit/V1/Client/AppConnectionsServiceClientTest.php @@ -0,0 +1,1146 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return AppConnectionsServiceClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new AppConnectionsServiceClient($options); + } + + /** @test */ + public function createAppConnectionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/createAppConnectionTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $displayName = 'displayName1615086568'; + $uid = 'uid115792'; + $expectedResponse = new AppConnection(); + $expectedResponse->setName($name); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setUid($uid); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createAppConnectionTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $appConnection = new AppConnection(); + $appConnectionName = 'appConnectionName-1608104182'; + $appConnection->setName($appConnectionName); + $appConnectionType = Type::TYPE_UNSPECIFIED; + $appConnection->setType($appConnectionType); + $appConnectionApplicationEndpoint = new ApplicationEndpoint(); + $applicationEndpointHost = 'applicationEndpointHost1976079949'; + $appConnectionApplicationEndpoint->setHost($applicationEndpointHost); + $applicationEndpointPort = 1976318246; + $appConnectionApplicationEndpoint->setPort($applicationEndpointPort); + $appConnection->setApplicationEndpoint($appConnectionApplicationEndpoint); + $request = (new CreateAppConnectionRequest()) + ->setParent($formattedParent) + ->setAppConnection($appConnection); + $response = $gapicClient->createAppConnection($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.beyondcorp.appconnections.v1.AppConnectionsService/CreateAppConnection', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getAppConnection(); + $this->assertProtobufEquals($appConnection, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createAppConnectionTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function createAppConnectionExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/createAppConnectionTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $appConnection = new AppConnection(); + $appConnectionName = 'appConnectionName-1608104182'; + $appConnection->setName($appConnectionName); + $appConnectionType = Type::TYPE_UNSPECIFIED; + $appConnection->setType($appConnectionType); + $appConnectionApplicationEndpoint = new ApplicationEndpoint(); + $applicationEndpointHost = 'applicationEndpointHost1976079949'; + $appConnectionApplicationEndpoint->setHost($applicationEndpointHost); + $applicationEndpointPort = 1976318246; + $appConnectionApplicationEndpoint->setPort($applicationEndpointPort); + $appConnection->setApplicationEndpoint($appConnectionApplicationEndpoint); + $request = (new CreateAppConnectionRequest()) + ->setParent($formattedParent) + ->setAppConnection($appConnection); + $response = $gapicClient->createAppConnection($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createAppConnectionTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function deleteAppConnectionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/deleteAppConnectionTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new GPBEmpty(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/deleteAppConnectionTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->appConnectionName('[PROJECT]', '[LOCATION]', '[APP_CONNECTION]'); + $request = (new DeleteAppConnectionRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteAppConnection($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.beyondcorp.appconnections.v1.AppConnectionsService/DeleteAppConnection', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteAppConnectionTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function deleteAppConnectionExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/deleteAppConnectionTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->appConnectionName('[PROJECT]', '[LOCATION]', '[APP_CONNECTION]'); + $request = (new DeleteAppConnectionRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteAppConnection($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteAppConnectionTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function getAppConnectionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $displayName = 'displayName1615086568'; + $uid = 'uid115792'; + $expectedResponse = new AppConnection(); + $expectedResponse->setName($name2); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setUid($uid); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->appConnectionName('[PROJECT]', '[LOCATION]', '[APP_CONNECTION]'); + $request = (new GetAppConnectionRequest()) + ->setName($formattedName); + $response = $gapicClient->getAppConnection($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.beyondcorp.appconnections.v1.AppConnectionsService/GetAppConnection', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getAppConnectionExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->appConnectionName('[PROJECT]', '[LOCATION]', '[APP_CONNECTION]'); + $request = (new GetAppConnectionRequest()) + ->setName($formattedName); + try { + $gapicClient->getAppConnection($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listAppConnectionsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $appConnectionsElement = new AppConnection(); + $appConnections = [ + $appConnectionsElement, + ]; + $expectedResponse = new ListAppConnectionsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setAppConnections($appConnections); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListAppConnectionsRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listAppConnections($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getAppConnections()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.beyondcorp.appconnections.v1.AppConnectionsService/ListAppConnections', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listAppConnectionsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListAppConnectionsRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listAppConnections($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function resolveAppConnectionsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $appConnectionDetailsElement = new AppConnectionDetails(); + $appConnectionDetails = [ + $appConnectionDetailsElement, + ]; + $expectedResponse = new ResolveAppConnectionsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setAppConnectionDetails($appConnectionDetails); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $formattedAppConnectorId = $gapicClient->appConnectorName('[PROJECT]', '[LOCATION]', '[APP_CONNECTOR]'); + $request = (new ResolveAppConnectionsRequest()) + ->setParent($formattedParent) + ->setAppConnectorId($formattedAppConnectorId); + $response = $gapicClient->resolveAppConnections($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getAppConnectionDetails()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.beyondcorp.appconnections.v1.AppConnectionsService/ResolveAppConnections', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getAppConnectorId(); + $this->assertProtobufEquals($formattedAppConnectorId, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function resolveAppConnectionsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $formattedAppConnectorId = $gapicClient->appConnectorName('[PROJECT]', '[LOCATION]', '[APP_CONNECTOR]'); + $request = (new ResolveAppConnectionsRequest()) + ->setParent($formattedParent) + ->setAppConnectorId($formattedAppConnectorId); + try { + $gapicClient->resolveAppConnections($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function updateAppConnectionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/updateAppConnectionTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $displayName = 'displayName1615086568'; + $uid = 'uid115792'; + $expectedResponse = new AppConnection(); + $expectedResponse->setName($name); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setUid($uid); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/updateAppConnectionTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $updateMask = new FieldMask(); + $appConnection = new AppConnection(); + $appConnectionName = 'appConnectionName-1608104182'; + $appConnection->setName($appConnectionName); + $appConnectionType = Type::TYPE_UNSPECIFIED; + $appConnection->setType($appConnectionType); + $appConnectionApplicationEndpoint = new ApplicationEndpoint(); + $applicationEndpointHost = 'applicationEndpointHost1976079949'; + $appConnectionApplicationEndpoint->setHost($applicationEndpointHost); + $applicationEndpointPort = 1976318246; + $appConnectionApplicationEndpoint->setPort($applicationEndpointPort); + $appConnection->setApplicationEndpoint($appConnectionApplicationEndpoint); + $request = (new UpdateAppConnectionRequest()) + ->setUpdateMask($updateMask) + ->setAppConnection($appConnection); + $response = $gapicClient->updateAppConnection($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.beyondcorp.appconnections.v1.AppConnectionsService/UpdateAppConnection', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getUpdateMask(); + $this->assertProtobufEquals($updateMask, $actualValue); + $actualValue = $actualApiRequestObject->getAppConnection(); + $this->assertProtobufEquals($appConnection, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateAppConnectionTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function updateAppConnectionExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/updateAppConnectionTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $updateMask = new FieldMask(); + $appConnection = new AppConnection(); + $appConnectionName = 'appConnectionName-1608104182'; + $appConnection->setName($appConnectionName); + $appConnectionType = Type::TYPE_UNSPECIFIED; + $appConnection->setType($appConnectionType); + $appConnectionApplicationEndpoint = new ApplicationEndpoint(); + $applicationEndpointHost = 'applicationEndpointHost1976079949'; + $appConnectionApplicationEndpoint->setHost($applicationEndpointHost); + $applicationEndpointPort = 1976318246; + $appConnectionApplicationEndpoint->setPort($applicationEndpointPort); + $appConnection->setApplicationEndpoint($appConnectionApplicationEndpoint); + $request = (new UpdateAppConnectionRequest()) + ->setUpdateMask($updateMask) + ->setAppConnection($appConnection); + $response = $gapicClient->updateAppConnection($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateAppConnectionTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function getLocationTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $locationId = 'locationId552319461'; + $displayName = 'displayName1615086568'; + $expectedResponse = new Location(); + $expectedResponse->setName($name2); + $expectedResponse->setLocationId($locationId); + $expectedResponse->setDisplayName($displayName); + $transport->addResponse($expectedResponse); + $request = new GetLocationRequest(); + $response = $gapicClient->getLocation($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.location.Locations/GetLocation', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getLocationExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + $request = new GetLocationRequest(); + try { + $gapicClient->getLocation($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listLocationsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $locationsElement = new Location(); + $locations = [ + $locationsElement, + ]; + $expectedResponse = new ListLocationsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setLocations($locations); + $transport->addResponse($expectedResponse); + $request = new ListLocationsRequest(); + $response = $gapicClient->listLocations($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getLocations()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.location.Locations/ListLocations', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listLocationsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + $request = new ListLocationsRequest(); + try { + $gapicClient->listLocations($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getIamPolicyTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $version = 351608024; + $etag = '21'; + $expectedResponse = new Policy(); + $expectedResponse->setVersion($version); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + $response = $gapicClient->getIamPolicy($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.iam.v1.IAMPolicy/GetIamPolicy', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getIamPolicyExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $resource = 'resource-341064690'; + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + try { + $gapicClient->getIamPolicy($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function setIamPolicyTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $version = 351608024; + $etag = '21'; + $expectedResponse = new Policy(); + $expectedResponse->setVersion($version); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $policy = new Policy(); + $request = (new SetIamPolicyRequest()) + ->setResource($resource) + ->setPolicy($policy); + $response = $gapicClient->setIamPolicy($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.iam.v1.IAMPolicy/SetIamPolicy', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $actualValue = $actualRequestObject->getPolicy(); + $this->assertProtobufEquals($policy, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function setIamPolicyExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $resource = 'resource-341064690'; + $policy = new Policy(); + $request = (new SetIamPolicyRequest()) + ->setResource($resource) + ->setPolicy($policy); + try { + $gapicClient->setIamPolicy($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function testIamPermissionsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new TestIamPermissionsResponse(); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $permissions = []; + $request = (new TestIamPermissionsRequest()) + ->setResource($resource) + ->setPermissions($permissions); + $response = $gapicClient->testIamPermissions($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.iam.v1.IAMPolicy/TestIamPermissions', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $actualValue = $actualRequestObject->getPermissions(); + $this->assertProtobufEquals($permissions, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function testIamPermissionsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $resource = 'resource-341064690'; + $permissions = []; + $request = (new TestIamPermissionsRequest()) + ->setResource($resource) + ->setPermissions($permissions); + try { + $gapicClient->testIamPermissions($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createAppConnectionAsyncTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/createAppConnectionTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $displayName = 'displayName1615086568'; + $uid = 'uid115792'; + $expectedResponse = new AppConnection(); + $expectedResponse->setName($name); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setUid($uid); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createAppConnectionTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $appConnection = new AppConnection(); + $appConnectionName = 'appConnectionName-1608104182'; + $appConnection->setName($appConnectionName); + $appConnectionType = Type::TYPE_UNSPECIFIED; + $appConnection->setType($appConnectionType); + $appConnectionApplicationEndpoint = new ApplicationEndpoint(); + $applicationEndpointHost = 'applicationEndpointHost1976079949'; + $appConnectionApplicationEndpoint->setHost($applicationEndpointHost); + $applicationEndpointPort = 1976318246; + $appConnectionApplicationEndpoint->setPort($applicationEndpointPort); + $appConnection->setApplicationEndpoint($appConnectionApplicationEndpoint); + $request = (new CreateAppConnectionRequest()) + ->setParent($formattedParent) + ->setAppConnection($appConnection); + $response = $gapicClient->createAppConnectionAsync($request)->wait(); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.beyondcorp.appconnections.v1.AppConnectionsService/CreateAppConnection', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getAppConnection(); + $this->assertProtobufEquals($appConnection, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createAppConnectionTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } +} diff --git a/BeyondCorpAppConnectors/samples/V1/AppConnectorsServiceClient/create_app_connector.php b/BeyondCorpAppConnectors/samples/V1/AppConnectorsServiceClient/create_app_connector.php index 8ebe933a49b2..7c3dfa1f4529 100644 --- a/BeyondCorpAppConnectors/samples/V1/AppConnectorsServiceClient/create_app_connector.php +++ b/BeyondCorpAppConnectors/samples/V1/AppConnectorsServiceClient/create_app_connector.php @@ -27,7 +27,8 @@ use Google\ApiCore\OperationResponse; use Google\Cloud\BeyondCorp\AppConnectors\V1\AppConnector; use Google\Cloud\BeyondCorp\AppConnectors\V1\AppConnector\PrincipalInfo; -use Google\Cloud\BeyondCorp\AppConnectors\V1\AppConnectorsServiceClient; +use Google\Cloud\BeyondCorp\AppConnectors\V1\Client\AppConnectorsServiceClient; +use Google\Cloud\BeyondCorp\AppConnectors\V1\CreateAppConnectorRequest; use Google\Rpc\Status; /** @@ -44,16 +45,19 @@ function create_app_connector_sample(string $formattedParent, string $appConnect // Create a client. $appConnectorsServiceClient = new AppConnectorsServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $appConnectorPrincipalInfo = new PrincipalInfo(); $appConnector = (new AppConnector()) ->setName($appConnectorName) ->setPrincipalInfo($appConnectorPrincipalInfo); + $request = (new CreateAppConnectorRequest()) + ->setParent($formattedParent) + ->setAppConnector($appConnector); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $appConnectorsServiceClient->createAppConnector($formattedParent, $appConnector); + $response = $appConnectorsServiceClient->createAppConnector($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/BeyondCorpAppConnectors/samples/V1/AppConnectorsServiceClient/delete_app_connector.php b/BeyondCorpAppConnectors/samples/V1/AppConnectorsServiceClient/delete_app_connector.php index 0079ce840a80..55b4c09ec420 100644 --- a/BeyondCorpAppConnectors/samples/V1/AppConnectorsServiceClient/delete_app_connector.php +++ b/BeyondCorpAppConnectors/samples/V1/AppConnectorsServiceClient/delete_app_connector.php @@ -25,7 +25,8 @@ // [START beyondcorp_v1_generated_AppConnectorsService_DeleteAppConnector_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\BeyondCorp\AppConnectors\V1\AppConnectorsServiceClient; +use Google\Cloud\BeyondCorp\AppConnectors\V1\Client\AppConnectorsServiceClient; +use Google\Cloud\BeyondCorp\AppConnectors\V1\DeleteAppConnectorRequest; use Google\Rpc\Status; /** @@ -40,10 +41,14 @@ function delete_app_connector_sample(string $formattedName): void // Create a client. $appConnectorsServiceClient = new AppConnectorsServiceClient(); + // Prepare the request message. + $request = (new DeleteAppConnectorRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $appConnectorsServiceClient->deleteAppConnector($formattedName); + $response = $appConnectorsServiceClient->deleteAppConnector($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/BeyondCorpAppConnectors/samples/V1/AppConnectorsServiceClient/get_app_connector.php b/BeyondCorpAppConnectors/samples/V1/AppConnectorsServiceClient/get_app_connector.php index 04aea7df5abe..69769d7d5b5f 100644 --- a/BeyondCorpAppConnectors/samples/V1/AppConnectorsServiceClient/get_app_connector.php +++ b/BeyondCorpAppConnectors/samples/V1/AppConnectorsServiceClient/get_app_connector.php @@ -25,7 +25,8 @@ // [START beyondcorp_v1_generated_AppConnectorsService_GetAppConnector_sync] use Google\ApiCore\ApiException; use Google\Cloud\BeyondCorp\AppConnectors\V1\AppConnector; -use Google\Cloud\BeyondCorp\AppConnectors\V1\AppConnectorsServiceClient; +use Google\Cloud\BeyondCorp\AppConnectors\V1\Client\AppConnectorsServiceClient; +use Google\Cloud\BeyondCorp\AppConnectors\V1\GetAppConnectorRequest; /** * Gets details of a single AppConnector. @@ -39,10 +40,14 @@ function get_app_connector_sample(string $formattedName): void // Create a client. $appConnectorsServiceClient = new AppConnectorsServiceClient(); + // Prepare the request message. + $request = (new GetAppConnectorRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var AppConnector $response */ - $response = $appConnectorsServiceClient->getAppConnector($formattedName); + $response = $appConnectorsServiceClient->getAppConnector($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BeyondCorpAppConnectors/samples/V1/AppConnectorsServiceClient/get_iam_policy.php b/BeyondCorpAppConnectors/samples/V1/AppConnectorsServiceClient/get_iam_policy.php index f347567b3f0d..1097dcd81a59 100644 --- a/BeyondCorpAppConnectors/samples/V1/AppConnectorsServiceClient/get_iam_policy.php +++ b/BeyondCorpAppConnectors/samples/V1/AppConnectorsServiceClient/get_iam_policy.php @@ -24,7 +24,8 @@ // [START beyondcorp_v1_generated_AppConnectorsService_GetIamPolicy_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BeyondCorp\AppConnectors\V1\AppConnectorsServiceClient; +use Google\Cloud\BeyondCorp\AppConnectors\V1\Client\AppConnectorsServiceClient; +use Google\Cloud\Iam\V1\GetIamPolicyRequest; use Google\Cloud\Iam\V1\Policy; /** @@ -39,10 +40,14 @@ function get_iam_policy_sample(string $resource): void // Create a client. $appConnectorsServiceClient = new AppConnectorsServiceClient(); + // Prepare the request message. + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + // Call the API and handle any network failures. try { /** @var Policy $response */ - $response = $appConnectorsServiceClient->getIamPolicy($resource); + $response = $appConnectorsServiceClient->getIamPolicy($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BeyondCorpAppConnectors/samples/V1/AppConnectorsServiceClient/get_location.php b/BeyondCorpAppConnectors/samples/V1/AppConnectorsServiceClient/get_location.php index 067f5ba17bb5..5943c7c4d8d7 100644 --- a/BeyondCorpAppConnectors/samples/V1/AppConnectorsServiceClient/get_location.php +++ b/BeyondCorpAppConnectors/samples/V1/AppConnectorsServiceClient/get_location.php @@ -24,7 +24,8 @@ // [START beyondcorp_v1_generated_AppConnectorsService_GetLocation_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BeyondCorp\AppConnectors\V1\AppConnectorsServiceClient; +use Google\Cloud\BeyondCorp\AppConnectors\V1\Client\AppConnectorsServiceClient; +use Google\Cloud\Location\GetLocationRequest; use Google\Cloud\Location\Location; /** @@ -41,10 +42,13 @@ function get_location_sample(): void // Create a client. $appConnectorsServiceClient = new AppConnectorsServiceClient(); + // Prepare the request message. + $request = new GetLocationRequest(); + // Call the API and handle any network failures. try { /** @var Location $response */ - $response = $appConnectorsServiceClient->getLocation(); + $response = $appConnectorsServiceClient->getLocation($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BeyondCorpAppConnectors/samples/V1/AppConnectorsServiceClient/list_app_connectors.php b/BeyondCorpAppConnectors/samples/V1/AppConnectorsServiceClient/list_app_connectors.php index 4aa8cf90e2de..18aa53568a68 100644 --- a/BeyondCorpAppConnectors/samples/V1/AppConnectorsServiceClient/list_app_connectors.php +++ b/BeyondCorpAppConnectors/samples/V1/AppConnectorsServiceClient/list_app_connectors.php @@ -26,7 +26,8 @@ use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; use Google\Cloud\BeyondCorp\AppConnectors\V1\AppConnector; -use Google\Cloud\BeyondCorp\AppConnectors\V1\AppConnectorsServiceClient; +use Google\Cloud\BeyondCorp\AppConnectors\V1\Client\AppConnectorsServiceClient; +use Google\Cloud\BeyondCorp\AppConnectors\V1\ListAppConnectorsRequest; /** * Lists AppConnectors in a given project and location. @@ -40,10 +41,14 @@ function list_app_connectors_sample(string $formattedParent): void // Create a client. $appConnectorsServiceClient = new AppConnectorsServiceClient(); + // Prepare the request message. + $request = (new ListAppConnectorsRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $appConnectorsServiceClient->listAppConnectors($formattedParent); + $response = $appConnectorsServiceClient->listAppConnectors($request); /** @var AppConnector $element */ foreach ($response as $element) { diff --git a/BeyondCorpAppConnectors/samples/V1/AppConnectorsServiceClient/list_locations.php b/BeyondCorpAppConnectors/samples/V1/AppConnectorsServiceClient/list_locations.php index 499d4cdf02d7..d1d9ce37dedc 100644 --- a/BeyondCorpAppConnectors/samples/V1/AppConnectorsServiceClient/list_locations.php +++ b/BeyondCorpAppConnectors/samples/V1/AppConnectorsServiceClient/list_locations.php @@ -25,7 +25,8 @@ // [START beyondcorp_v1_generated_AppConnectorsService_ListLocations_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; -use Google\Cloud\BeyondCorp\AppConnectors\V1\AppConnectorsServiceClient; +use Google\Cloud\BeyondCorp\AppConnectors\V1\Client\AppConnectorsServiceClient; +use Google\Cloud\Location\ListLocationsRequest; use Google\Cloud\Location\Location; /** @@ -42,10 +43,13 @@ function list_locations_sample(): void // Create a client. $appConnectorsServiceClient = new AppConnectorsServiceClient(); + // Prepare the request message. + $request = new ListLocationsRequest(); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $appConnectorsServiceClient->listLocations(); + $response = $appConnectorsServiceClient->listLocations($request); /** @var Location $element */ foreach ($response as $element) { diff --git a/BeyondCorpAppConnectors/samples/V1/AppConnectorsServiceClient/report_status.php b/BeyondCorpAppConnectors/samples/V1/AppConnectorsServiceClient/report_status.php index f7db25092e9c..fc566ebf071c 100644 --- a/BeyondCorpAppConnectors/samples/V1/AppConnectorsServiceClient/report_status.php +++ b/BeyondCorpAppConnectors/samples/V1/AppConnectorsServiceClient/report_status.php @@ -26,7 +26,8 @@ use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; use Google\Cloud\BeyondCorp\AppConnectors\V1\AppConnector; -use Google\Cloud\BeyondCorp\AppConnectors\V1\AppConnectorsServiceClient; +use Google\Cloud\BeyondCorp\AppConnectors\V1\Client\AppConnectorsServiceClient; +use Google\Cloud\BeyondCorp\AppConnectors\V1\ReportStatusRequest; use Google\Cloud\BeyondCorp\AppConnectors\V1\ResourceInfo; use Google\Rpc\Status; @@ -43,14 +44,17 @@ function report_status_sample(string $formattedAppConnector, string $resourceInf // Create a client. $appConnectorsServiceClient = new AppConnectorsServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $resourceInfo = (new ResourceInfo()) ->setId($resourceInfoId); + $request = (new ReportStatusRequest()) + ->setAppConnector($formattedAppConnector) + ->setResourceInfo($resourceInfo); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $appConnectorsServiceClient->reportStatus($formattedAppConnector, $resourceInfo); + $response = $appConnectorsServiceClient->reportStatus($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/BeyondCorpAppConnectors/samples/V1/AppConnectorsServiceClient/set_iam_policy.php b/BeyondCorpAppConnectors/samples/V1/AppConnectorsServiceClient/set_iam_policy.php index 3a2278e5479d..780821be06c8 100644 --- a/BeyondCorpAppConnectors/samples/V1/AppConnectorsServiceClient/set_iam_policy.php +++ b/BeyondCorpAppConnectors/samples/V1/AppConnectorsServiceClient/set_iam_policy.php @@ -24,8 +24,9 @@ // [START beyondcorp_v1_generated_AppConnectorsService_SetIamPolicy_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BeyondCorp\AppConnectors\V1\AppConnectorsServiceClient; +use Google\Cloud\BeyondCorp\AppConnectors\V1\Client\AppConnectorsServiceClient; use Google\Cloud\Iam\V1\Policy; +use Google\Cloud\Iam\V1\SetIamPolicyRequest; /** * Sets the access control policy on the specified resource. Replaces @@ -42,13 +43,16 @@ function set_iam_policy_sample(string $resource): void // Create a client. $appConnectorsServiceClient = new AppConnectorsServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $policy = new Policy(); + $request = (new SetIamPolicyRequest()) + ->setResource($resource) + ->setPolicy($policy); // Call the API and handle any network failures. try { /** @var Policy $response */ - $response = $appConnectorsServiceClient->setIamPolicy($resource, $policy); + $response = $appConnectorsServiceClient->setIamPolicy($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BeyondCorpAppConnectors/samples/V1/AppConnectorsServiceClient/test_iam_permissions.php b/BeyondCorpAppConnectors/samples/V1/AppConnectorsServiceClient/test_iam_permissions.php index ec6245eda28a..78f96c10fe71 100644 --- a/BeyondCorpAppConnectors/samples/V1/AppConnectorsServiceClient/test_iam_permissions.php +++ b/BeyondCorpAppConnectors/samples/V1/AppConnectorsServiceClient/test_iam_permissions.php @@ -24,7 +24,8 @@ // [START beyondcorp_v1_generated_AppConnectorsService_TestIamPermissions_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BeyondCorp\AppConnectors\V1\AppConnectorsServiceClient; +use Google\Cloud\BeyondCorp\AppConnectors\V1\Client\AppConnectorsServiceClient; +use Google\Cloud\Iam\V1\TestIamPermissionsRequest; use Google\Cloud\Iam\V1\TestIamPermissionsResponse; /** @@ -48,13 +49,16 @@ function test_iam_permissions_sample(string $resource, string $permissionsElemen // Create a client. $appConnectorsServiceClient = new AppConnectorsServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $permissions = [$permissionsElement,]; + $request = (new TestIamPermissionsRequest()) + ->setResource($resource) + ->setPermissions($permissions); // Call the API and handle any network failures. try { /** @var TestIamPermissionsResponse $response */ - $response = $appConnectorsServiceClient->testIamPermissions($resource, $permissions); + $response = $appConnectorsServiceClient->testIamPermissions($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BeyondCorpAppConnectors/samples/V1/AppConnectorsServiceClient/update_app_connector.php b/BeyondCorpAppConnectors/samples/V1/AppConnectorsServiceClient/update_app_connector.php index 658aa75b8c82..9ee772214c0f 100644 --- a/BeyondCorpAppConnectors/samples/V1/AppConnectorsServiceClient/update_app_connector.php +++ b/BeyondCorpAppConnectors/samples/V1/AppConnectorsServiceClient/update_app_connector.php @@ -27,7 +27,8 @@ use Google\ApiCore\OperationResponse; use Google\Cloud\BeyondCorp\AppConnectors\V1\AppConnector; use Google\Cloud\BeyondCorp\AppConnectors\V1\AppConnector\PrincipalInfo; -use Google\Cloud\BeyondCorp\AppConnectors\V1\AppConnectorsServiceClient; +use Google\Cloud\BeyondCorp\AppConnectors\V1\Client\AppConnectorsServiceClient; +use Google\Cloud\BeyondCorp\AppConnectors\V1\UpdateAppConnectorRequest; use Google\Protobuf\FieldMask; use Google\Rpc\Status; @@ -42,17 +43,20 @@ function update_app_connector_sample(string $appConnectorName): void // Create a client. $appConnectorsServiceClient = new AppConnectorsServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $updateMask = new FieldMask(); $appConnectorPrincipalInfo = new PrincipalInfo(); $appConnector = (new AppConnector()) ->setName($appConnectorName) ->setPrincipalInfo($appConnectorPrincipalInfo); + $request = (new UpdateAppConnectorRequest()) + ->setUpdateMask($updateMask) + ->setAppConnector($appConnector); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $appConnectorsServiceClient->updateAppConnector($updateMask, $appConnector); + $response = $appConnectorsServiceClient->updateAppConnector($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/BeyondCorpAppConnectors/src/V1/Client/AppConnectorsServiceClient.php b/BeyondCorpAppConnectors/src/V1/Client/AppConnectorsServiceClient.php new file mode 100644 index 000000000000..055ed7433fc2 --- /dev/null +++ b/BeyondCorpAppConnectors/src/V1/Client/AppConnectorsServiceClient.php @@ -0,0 +1,40 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/app_connectors_service_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/app_connectors_service_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/app_connectors_service_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/app_connectors_service_rest_client_config.php', + ], + ], + ]; + } + + /** + * Return an OperationsClient object with the same endpoint as $this. + * + * @return OperationsClient + */ + public function getOperationsClient() + { + return $this->operationsClient; + } + + /** + * Resume an existing long running operation that was previously started by a long + * running API method. If $methodName is not provided, or does not match a long + * running API method, then the operation can still be resumed, but the + * OperationResponse object will not deserialize the final response. + * + * @param string $operationName The name of the long running operation + * @param string $methodName The name of the method used to start the operation + * + * @return OperationResponse + */ + public function resumeOperation($operationName, $methodName = null) + { + $options = isset($this->descriptors[$methodName]['longRunning']) ? $this->descriptors[$methodName]['longRunning'] : []; + $operation = new OperationResponse($operationName, $this->getOperationsClient(), $options); + $operation->reload(); + return $operation; + } + + /** + * Formats a string containing the fully-qualified path to represent a + * app_connector resource. + * + * @param string $project + * @param string $location + * @param string $appConnector + * + * @return string The formatted app_connector resource. + */ + public static function appConnectorName(string $project, string $location, string $appConnector): string + { + return self::getPathTemplate('appConnector')->render([ + 'project' => $project, + 'location' => $location, + 'app_connector' => $appConnector, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a location + * resource. + * + * @param string $project + * @param string $location + * + * @return string The formatted location resource. + */ + public static function locationName(string $project, string $location): string + { + return self::getPathTemplate('location')->render([ + 'project' => $project, + 'location' => $location, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * Template: Pattern + * - appConnector: projects/{project}/locations/{location}/appConnectors/{app_connector} + * - location: projects/{project}/locations/{location} + * + * The optional $template argument can be supplied to specify a particular pattern, + * and must match one of the templates listed above. If no $template argument is + * provided, or if the $template argument does not match one of the templates + * listed, then parseName will check each of the supported templates, and return + * the first match. + * + * @param string $formattedName The formatted name string + * @param string $template Optional name of template to match + * + * @return array An associative array from name component IDs to component values. + * + * @throws ValidationException If $formattedName could not be matched. + */ + public static function parseName(string $formattedName, string $template = null): array + { + return self::parseFormattedName($formattedName, $template); + } + + /** + * Constructor. + * + * @param array $options { + * Optional. Options for configuring the service API wrapper. + * + * @type string $apiEndpoint + * The address of the API remote host. May optionally include the port, formatted + * as ":". Default 'beyondcorp.googleapis.com:443'. + * @type string|array|FetchAuthTokenInterface|CredentialsWrapper $credentials + * The credentials to be used by the client to authorize API calls. This option + * accepts either a path to a credentials file, or a decoded credentials file as a + * PHP array. + * *Advanced usage*: In addition, this option can also accept a pre-constructed + * {@see \Google\Auth\FetchAuthTokenInterface} object or + * {@see \Google\ApiCore\CredentialsWrapper} object. Note that when one of these + * objects are provided, any settings in $credentialsConfig will be ignored. + * @type array $credentialsConfig + * Options used to configure credentials, including auth token caching, for the + * client. For a full list of supporting configuration options, see + * {@see \Google\ApiCore\CredentialsWrapper::build()} . + * @type bool $disableRetries + * Determines whether or not retries defined by the client configuration should be + * disabled. Defaults to `false`. + * @type string|array $clientConfig + * Client method configuration, including retry settings. This option can be either + * a path to a JSON file, or a PHP array containing the decoded JSON data. By + * default this settings points to the default client config file, which is + * provided in the resources folder. + * @type string|TransportInterface $transport + * The transport used for executing network requests. May be either the string + * `rest` or `grpc`. Defaults to `grpc` if gRPC support is detected on the system. + * *Advanced usage*: Additionally, it is possible to pass in an already + * instantiated {@see \Google\ApiCore\Transport\TransportInterface} object. Note + * that when this object is provided, any settings in $transportConfig, and any + * $apiEndpoint setting, will be ignored. + * @type array $transportConfig + * Configuration options that will be used to construct the transport. Options for + * each supported transport type should be passed in a key for that transport. For + * example: + * $transportConfig = [ + * 'grpc' => [...], + * 'rest' => [...], + * ]; + * See the {@see \Google\ApiCore\Transport\GrpcTransport::build()} and + * {@see \Google\ApiCore\Transport\RestTransport::build()} methods for the + * supported options. + * @type callable $clientCertSource + * A callable which returns the client cert as a string. This can be used to + * provide a certificate and private key to the transport layer for mTLS. + * } + * + * @throws ValidationException + */ + public function __construct(array $options = []) + { + $clientOptions = $this->buildClientOptions($options); + $this->setClientOptions($clientOptions); + $this->operationsClient = $this->createOperationsClient($clientOptions); + } + + /** Handles execution of the async variants for each documented method. */ + public function __call($method, $args) + { + if (substr($method, -5) !== 'Async') { + trigger_error('Call to undefined method ' . __CLASS__ . "::$method()", E_USER_ERROR); + } + + array_unshift($args, substr($method, 0, -5)); + return call_user_func_array([$this, 'startAsyncCall'], $args); + } + + /** + * Creates a new AppConnector in a given project and location. + * + * The async variant is {@see self::createAppConnectorAsync()} . + * + * @param CreateAppConnectorRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function createAppConnector(CreateAppConnectorRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('CreateAppConnector', $request, $callOptions)->wait(); + } + + /** + * Deletes a single AppConnector. + * + * The async variant is {@see self::deleteAppConnectorAsync()} . + * + * @param DeleteAppConnectorRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function deleteAppConnector(DeleteAppConnectorRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('DeleteAppConnector', $request, $callOptions)->wait(); + } + + /** + * Gets details of a single AppConnector. + * + * The async variant is {@see self::getAppConnectorAsync()} . + * + * @param GetAppConnectorRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return AppConnector + * + * @throws ApiException Thrown if the API call fails. + */ + public function getAppConnector(GetAppConnectorRequest $request, array $callOptions = []): AppConnector + { + return $this->startApiCall('GetAppConnector', $request, $callOptions)->wait(); + } + + /** + * Lists AppConnectors in a given project and location. + * + * The async variant is {@see self::listAppConnectorsAsync()} . + * + * @param ListAppConnectorsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listAppConnectors(ListAppConnectorsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListAppConnectors', $request, $callOptions); + } + + /** + * Report status for a given connector. + * + * The async variant is {@see self::reportStatusAsync()} . + * + * @param ReportStatusRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function reportStatus(ReportStatusRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('ReportStatus', $request, $callOptions)->wait(); + } + + /** + * Updates the parameters of a single AppConnector. + * + * The async variant is {@see self::updateAppConnectorAsync()} . + * + * @param UpdateAppConnectorRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function updateAppConnector(UpdateAppConnectorRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('UpdateAppConnector', $request, $callOptions)->wait(); + } + + /** + * Gets information about a location. + * + * The async variant is {@see self::getLocationAsync()} . + * + * @param GetLocationRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Location + * + * @throws ApiException Thrown if the API call fails. + */ + public function getLocation(GetLocationRequest $request, array $callOptions = []): Location + { + return $this->startApiCall('GetLocation', $request, $callOptions)->wait(); + } + + /** + * Lists information about the supported locations for this service. + * + * The async variant is {@see self::listLocationsAsync()} . + * + * @param ListLocationsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listLocations(ListLocationsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListLocations', $request, $callOptions); + } + + /** + * Gets the access control policy for a resource. Returns an empty policy + if the resource exists and does not have a policy set. + * + * The async variant is {@see self::getIamPolicyAsync()} . + * + * @param GetIamPolicyRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Policy + * + * @throws ApiException Thrown if the API call fails. + */ + public function getIamPolicy(GetIamPolicyRequest $request, array $callOptions = []): Policy + { + return $this->startApiCall('GetIamPolicy', $request, $callOptions)->wait(); + } + + /** + * Sets the access control policy on the specified resource. Replaces + any existing policy. + + Can return `NOT_FOUND`, `INVALID_ARGUMENT`, and `PERMISSION_DENIED` + errors. + * + * The async variant is {@see self::setIamPolicyAsync()} . + * + * @param SetIamPolicyRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Policy + * + * @throws ApiException Thrown if the API call fails. + */ + public function setIamPolicy(SetIamPolicyRequest $request, array $callOptions = []): Policy + { + return $this->startApiCall('SetIamPolicy', $request, $callOptions)->wait(); + } + + /** + * Returns permissions that a caller has on the specified resource. If the + resource does not exist, this will return an empty set of + permissions, not a `NOT_FOUND` error. + + Note: This operation is designed to be used for building + permission-aware UIs and command-line tools, not for authorization + checking. This operation may "fail open" without warning. + * + * The async variant is {@see self::testIamPermissionsAsync()} . + * + * @param TestIamPermissionsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return TestIamPermissionsResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function testIamPermissions(TestIamPermissionsRequest $request, array $callOptions = []): TestIamPermissionsResponse + { + return $this->startApiCall('TestIamPermissions', $request, $callOptions)->wait(); + } +} diff --git a/BeyondCorpAppConnectors/src/V1/CreateAppConnectorRequest.php b/BeyondCorpAppConnectors/src/V1/CreateAppConnectorRequest.php index e23e1c81b788..d927f6cb34e3 100644 --- a/BeyondCorpAppConnectors/src/V1/CreateAppConnectorRequest.php +++ b/BeyondCorpAppConnectors/src/V1/CreateAppConnectorRequest.php @@ -61,6 +61,29 @@ class CreateAppConnectorRequest extends \Google\Protobuf\Internal\Message */ private $validate_only = false; + /** + * @param string $parent Required. The resource project name of the AppConnector location using the + * form: `projects/{project_id}/locations/{location_id}` + * Please see {@see AppConnectorsServiceClient::locationName()} for help formatting this field. + * @param \Google\Cloud\BeyondCorp\AppConnectors\V1\AppConnector $appConnector Required. A BeyondCorp AppConnector resource. + * @param string $appConnectorId Optional. User-settable AppConnector resource ID. + * + * * Must start with a letter. + * * Must contain between 4-63 characters from `/[a-z][0-9]-/`. + * * Must end with a number or a letter. + * + * @return \Google\Cloud\BeyondCorp\AppConnectors\V1\CreateAppConnectorRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\BeyondCorp\AppConnectors\V1\AppConnector $appConnector, string $appConnectorId): self + { + return (new self()) + ->setParent($parent) + ->setAppConnector($appConnector) + ->setAppConnectorId($appConnectorId); + } + /** * Constructor. * diff --git a/BeyondCorpAppConnectors/src/V1/DeleteAppConnectorRequest.php b/BeyondCorpAppConnectors/src/V1/DeleteAppConnectorRequest.php index a19010ce0696..8daff7f552be 100644 --- a/BeyondCorpAppConnectors/src/V1/DeleteAppConnectorRequest.php +++ b/BeyondCorpAppConnectors/src/V1/DeleteAppConnectorRequest.php @@ -46,6 +46,21 @@ class DeleteAppConnectorRequest extends \Google\Protobuf\Internal\Message */ private $validate_only = false; + /** + * @param string $name Required. BeyondCorp AppConnector name using the form: + * `projects/{project_id}/locations/{location_id}/appConnectors/{app_connector_id}` + * Please see {@see AppConnectorsServiceClient::appConnectorName()} for help formatting this field. + * + * @return \Google\Cloud\BeyondCorp\AppConnectors\V1\DeleteAppConnectorRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/BeyondCorpAppConnectors/src/V1/GetAppConnectorRequest.php b/BeyondCorpAppConnectors/src/V1/GetAppConnectorRequest.php index f81f951b06aa..b6e027fb8ff9 100644 --- a/BeyondCorpAppConnectors/src/V1/GetAppConnectorRequest.php +++ b/BeyondCorpAppConnectors/src/V1/GetAppConnectorRequest.php @@ -23,6 +23,21 @@ class GetAppConnectorRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. BeyondCorp AppConnector name using the form: + * `projects/{project_id}/locations/{location_id}/appConnectors/{app_connector_id}` + * Please see {@see AppConnectorsServiceClient::appConnectorName()} for help formatting this field. + * + * @return \Google\Cloud\BeyondCorp\AppConnectors\V1\GetAppConnectorRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/BeyondCorpAppConnectors/src/V1/ListAppConnectorsRequest.php b/BeyondCorpAppConnectors/src/V1/ListAppConnectorsRequest.php index e62b89705ad8..733116c6737e 100644 --- a/BeyondCorpAppConnectors/src/V1/ListAppConnectorsRequest.php +++ b/BeyondCorpAppConnectors/src/V1/ListAppConnectorsRequest.php @@ -56,6 +56,21 @@ class ListAppConnectorsRequest extends \Google\Protobuf\Internal\Message */ private $order_by = ''; + /** + * @param string $parent Required. The resource name of the AppConnector location using the form: + * `projects/{project_id}/locations/{location_id}` + * Please see {@see AppConnectorsServiceClient::locationName()} for help formatting this field. + * + * @return \Google\Cloud\BeyondCorp\AppConnectors\V1\ListAppConnectorsRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/BeyondCorpAppConnectors/src/V1/ReportStatusRequest.php b/BeyondCorpAppConnectors/src/V1/ReportStatusRequest.php index d4366cdadf91..e3f04afb0147 100644 --- a/BeyondCorpAppConnectors/src/V1/ReportStatusRequest.php +++ b/BeyondCorpAppConnectors/src/V1/ReportStatusRequest.php @@ -52,6 +52,23 @@ class ReportStatusRequest extends \Google\Protobuf\Internal\Message */ private $validate_only = false; + /** + * @param string $appConnector Required. BeyondCorp Connector name using the form: + * `projects/{project_id}/locations/{location_id}/connectors/{connector}` + * Please see {@see AppConnectorsServiceClient::appConnectorName()} for help formatting this field. + * @param \Google\Cloud\BeyondCorp\AppConnectors\V1\ResourceInfo $resourceInfo Required. Resource info of the connector. + * + * @return \Google\Cloud\BeyondCorp\AppConnectors\V1\ReportStatusRequest + * + * @experimental + */ + public static function build(string $appConnector, \Google\Cloud\BeyondCorp\AppConnectors\V1\ResourceInfo $resourceInfo): self + { + return (new self()) + ->setAppConnector($appConnector) + ->setResourceInfo($resourceInfo); + } + /** * Constructor. * diff --git a/BeyondCorpAppConnectors/src/V1/UpdateAppConnectorRequest.php b/BeyondCorpAppConnectors/src/V1/UpdateAppConnectorRequest.php index 3346274e56a0..c4464ebe1dc4 100644 --- a/BeyondCorpAppConnectors/src/V1/UpdateAppConnectorRequest.php +++ b/BeyondCorpAppConnectors/src/V1/UpdateAppConnectorRequest.php @@ -56,6 +56,26 @@ class UpdateAppConnectorRequest extends \Google\Protobuf\Internal\Message */ private $validate_only = false; + /** + * @param \Google\Cloud\BeyondCorp\AppConnectors\V1\AppConnector $appConnector Required. AppConnector message with updated fields. Only supported fields + * specified in update_mask are updated. + * @param \Google\Protobuf\FieldMask $updateMask Required. Mask of fields to update. At least one path must be supplied in + * this field. The elements of the repeated paths field may only include these + * fields from [BeyondCorp.AppConnector]: + * * `labels` + * * `display_name` + * + * @return \Google\Cloud\BeyondCorp\AppConnectors\V1\UpdateAppConnectorRequest + * + * @experimental + */ + public static function build(\Google\Cloud\BeyondCorp\AppConnectors\V1\AppConnector $appConnector, \Google\Protobuf\FieldMask $updateMask): self + { + return (new self()) + ->setAppConnector($appConnector) + ->setUpdateMask($updateMask); + } + /** * Constructor. * diff --git a/BeyondCorpAppConnectors/src/V1/resources/app_connectors_service_descriptor_config.php b/BeyondCorpAppConnectors/src/V1/resources/app_connectors_service_descriptor_config.php index d04a3c4796d7..2f6d0ac9a2c9 100644 --- a/BeyondCorpAppConnectors/src/V1/resources/app_connectors_service_descriptor_config.php +++ b/BeyondCorpAppConnectors/src/V1/resources/app_connectors_service_descriptor_config.php @@ -12,6 +12,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'DeleteAppConnector' => [ 'longRunning' => [ @@ -22,6 +31,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'ReportStatus' => [ 'longRunning' => [ @@ -32,6 +50,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'app_connector', + 'fieldAccessors' => [ + 'getAppConnector', + ], + ], + ], ], 'UpdateAppConnector' => [ 'longRunning' => [ @@ -42,6 +69,28 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'app_connector.name', + 'fieldAccessors' => [ + 'getAppConnector', + 'getName', + ], + ], + ], + ], + 'GetAppConnector' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\BeyondCorp\AppConnectors\V1\AppConnector', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'ListAppConnectors' => [ 'pageStreaming' => [ @@ -52,8 +101,28 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getAppConnectors', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\BeyondCorp\AppConnectors\V1\ListAppConnectorsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'GetLocation' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Location\Location', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], 'interfaceOverride' => 'google.cloud.location.Locations', ], 'ListLocations' => [ @@ -65,17 +134,61 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getLocations', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\Location\ListLocationsResponse', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], 'interfaceOverride' => 'google.cloud.location.Locations', ], 'GetIamPolicy' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\Policy', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], 'interfaceOverride' => 'google.iam.v1.IAMPolicy', ], 'SetIamPolicy' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\Policy', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], 'interfaceOverride' => 'google.iam.v1.IAMPolicy', ], 'TestIamPermissions' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\TestIamPermissionsResponse', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], 'interfaceOverride' => 'google.iam.v1.IAMPolicy', ], + 'templateMap' => [ + 'appConnector' => 'projects/{project}/locations/{location}/appConnectors/{app_connector}', + 'location' => 'projects/{project}/locations/{location}', + ], ], ], ]; diff --git a/BeyondCorpAppConnectors/tests/Unit/V1/Client/AppConnectorsServiceClientTest.php b/BeyondCorpAppConnectors/tests/Unit/V1/Client/AppConnectorsServiceClientTest.php new file mode 100644 index 000000000000..bff4f852225f --- /dev/null +++ b/BeyondCorpAppConnectors/tests/Unit/V1/Client/AppConnectorsServiceClientTest.php @@ -0,0 +1,1173 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return AppConnectorsServiceClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new AppConnectorsServiceClient($options); + } + + /** @test */ + public function createAppConnectorTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/createAppConnectorTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $displayName = 'displayName1615086568'; + $uid = 'uid115792'; + $expectedResponse = new AppConnector(); + $expectedResponse->setName($name); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setUid($uid); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createAppConnectorTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $appConnector = new AppConnector(); + $appConnectorName = 'appConnectorName-1263736873'; + $appConnector->setName($appConnectorName); + $appConnectorPrincipalInfo = new PrincipalInfo(); + $appConnector->setPrincipalInfo($appConnectorPrincipalInfo); + $request = (new CreateAppConnectorRequest()) + ->setParent($formattedParent) + ->setAppConnector($appConnector); + $response = $gapicClient->createAppConnector($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.beyondcorp.appconnectors.v1.AppConnectorsService/CreateAppConnector', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getAppConnector(); + $this->assertProtobufEquals($appConnector, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createAppConnectorTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function createAppConnectorExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/createAppConnectorTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $appConnector = new AppConnector(); + $appConnectorName = 'appConnectorName-1263736873'; + $appConnector->setName($appConnectorName); + $appConnectorPrincipalInfo = new PrincipalInfo(); + $appConnector->setPrincipalInfo($appConnectorPrincipalInfo); + $request = (new CreateAppConnectorRequest()) + ->setParent($formattedParent) + ->setAppConnector($appConnector); + $response = $gapicClient->createAppConnector($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createAppConnectorTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function deleteAppConnectorTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/deleteAppConnectorTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new GPBEmpty(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/deleteAppConnectorTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->appConnectorName('[PROJECT]', '[LOCATION]', '[APP_CONNECTOR]'); + $request = (new DeleteAppConnectorRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteAppConnector($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.beyondcorp.appconnectors.v1.AppConnectorsService/DeleteAppConnector', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteAppConnectorTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function deleteAppConnectorExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/deleteAppConnectorTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->appConnectorName('[PROJECT]', '[LOCATION]', '[APP_CONNECTOR]'); + $request = (new DeleteAppConnectorRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteAppConnector($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteAppConnectorTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function getAppConnectorTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $displayName = 'displayName1615086568'; + $uid = 'uid115792'; + $expectedResponse = new AppConnector(); + $expectedResponse->setName($name2); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setUid($uid); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->appConnectorName('[PROJECT]', '[LOCATION]', '[APP_CONNECTOR]'); + $request = (new GetAppConnectorRequest()) + ->setName($formattedName); + $response = $gapicClient->getAppConnector($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.beyondcorp.appconnectors.v1.AppConnectorsService/GetAppConnector', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getAppConnectorExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->appConnectorName('[PROJECT]', '[LOCATION]', '[APP_CONNECTOR]'); + $request = (new GetAppConnectorRequest()) + ->setName($formattedName); + try { + $gapicClient->getAppConnector($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listAppConnectorsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $appConnectorsElement = new AppConnector(); + $appConnectors = [ + $appConnectorsElement, + ]; + $expectedResponse = new ListAppConnectorsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setAppConnectors($appConnectors); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListAppConnectorsRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listAppConnectors($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getAppConnectors()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.beyondcorp.appconnectors.v1.AppConnectorsService/ListAppConnectors', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listAppConnectorsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListAppConnectorsRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listAppConnectors($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function reportStatusTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/reportStatusTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $displayName = 'displayName1615086568'; + $uid = 'uid115792'; + $expectedResponse = new AppConnector(); + $expectedResponse->setName($name); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setUid($uid); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/reportStatusTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedAppConnector = $gapicClient->appConnectorName('[PROJECT]', '[LOCATION]', '[APP_CONNECTOR]'); + $resourceInfo = new ResourceInfo(); + $resourceInfoId = 'resourceInfoId-332404713'; + $resourceInfo->setId($resourceInfoId); + $request = (new ReportStatusRequest()) + ->setAppConnector($formattedAppConnector) + ->setResourceInfo($resourceInfo); + $response = $gapicClient->reportStatus($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.beyondcorp.appconnectors.v1.AppConnectorsService/ReportStatus', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getAppConnector(); + $this->assertProtobufEquals($formattedAppConnector, $actualValue); + $actualValue = $actualApiRequestObject->getResourceInfo(); + $this->assertProtobufEquals($resourceInfo, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/reportStatusTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function reportStatusExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/reportStatusTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedAppConnector = $gapicClient->appConnectorName('[PROJECT]', '[LOCATION]', '[APP_CONNECTOR]'); + $resourceInfo = new ResourceInfo(); + $resourceInfoId = 'resourceInfoId-332404713'; + $resourceInfo->setId($resourceInfoId); + $request = (new ReportStatusRequest()) + ->setAppConnector($formattedAppConnector) + ->setResourceInfo($resourceInfo); + $response = $gapicClient->reportStatus($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/reportStatusTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function updateAppConnectorTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/updateAppConnectorTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $displayName = 'displayName1615086568'; + $uid = 'uid115792'; + $expectedResponse = new AppConnector(); + $expectedResponse->setName($name); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setUid($uid); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/updateAppConnectorTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $updateMask = new FieldMask(); + $appConnector = new AppConnector(); + $appConnectorName = 'appConnectorName-1263736873'; + $appConnector->setName($appConnectorName); + $appConnectorPrincipalInfo = new PrincipalInfo(); + $appConnector->setPrincipalInfo($appConnectorPrincipalInfo); + $request = (new UpdateAppConnectorRequest()) + ->setUpdateMask($updateMask) + ->setAppConnector($appConnector); + $response = $gapicClient->updateAppConnector($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.beyondcorp.appconnectors.v1.AppConnectorsService/UpdateAppConnector', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getUpdateMask(); + $this->assertProtobufEquals($updateMask, $actualValue); + $actualValue = $actualApiRequestObject->getAppConnector(); + $this->assertProtobufEquals($appConnector, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateAppConnectorTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function updateAppConnectorExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/updateAppConnectorTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $updateMask = new FieldMask(); + $appConnector = new AppConnector(); + $appConnectorName = 'appConnectorName-1263736873'; + $appConnector->setName($appConnectorName); + $appConnectorPrincipalInfo = new PrincipalInfo(); + $appConnector->setPrincipalInfo($appConnectorPrincipalInfo); + $request = (new UpdateAppConnectorRequest()) + ->setUpdateMask($updateMask) + ->setAppConnector($appConnector); + $response = $gapicClient->updateAppConnector($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateAppConnectorTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function getLocationTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $locationId = 'locationId552319461'; + $displayName = 'displayName1615086568'; + $expectedResponse = new Location(); + $expectedResponse->setName($name2); + $expectedResponse->setLocationId($locationId); + $expectedResponse->setDisplayName($displayName); + $transport->addResponse($expectedResponse); + $request = new GetLocationRequest(); + $response = $gapicClient->getLocation($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.location.Locations/GetLocation', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getLocationExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + $request = new GetLocationRequest(); + try { + $gapicClient->getLocation($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listLocationsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $locationsElement = new Location(); + $locations = [ + $locationsElement, + ]; + $expectedResponse = new ListLocationsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setLocations($locations); + $transport->addResponse($expectedResponse); + $request = new ListLocationsRequest(); + $response = $gapicClient->listLocations($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getLocations()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.location.Locations/ListLocations', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listLocationsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + $request = new ListLocationsRequest(); + try { + $gapicClient->listLocations($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getIamPolicyTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $version = 351608024; + $etag = '21'; + $expectedResponse = new Policy(); + $expectedResponse->setVersion($version); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + $response = $gapicClient->getIamPolicy($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.iam.v1.IAMPolicy/GetIamPolicy', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getIamPolicyExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $resource = 'resource-341064690'; + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + try { + $gapicClient->getIamPolicy($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function setIamPolicyTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $version = 351608024; + $etag = '21'; + $expectedResponse = new Policy(); + $expectedResponse->setVersion($version); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $policy = new Policy(); + $request = (new SetIamPolicyRequest()) + ->setResource($resource) + ->setPolicy($policy); + $response = $gapicClient->setIamPolicy($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.iam.v1.IAMPolicy/SetIamPolicy', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $actualValue = $actualRequestObject->getPolicy(); + $this->assertProtobufEquals($policy, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function setIamPolicyExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $resource = 'resource-341064690'; + $policy = new Policy(); + $request = (new SetIamPolicyRequest()) + ->setResource($resource) + ->setPolicy($policy); + try { + $gapicClient->setIamPolicy($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function testIamPermissionsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new TestIamPermissionsResponse(); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $permissions = []; + $request = (new TestIamPermissionsRequest()) + ->setResource($resource) + ->setPermissions($permissions); + $response = $gapicClient->testIamPermissions($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.iam.v1.IAMPolicy/TestIamPermissions', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $actualValue = $actualRequestObject->getPermissions(); + $this->assertProtobufEquals($permissions, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function testIamPermissionsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $resource = 'resource-341064690'; + $permissions = []; + $request = (new TestIamPermissionsRequest()) + ->setResource($resource) + ->setPermissions($permissions); + try { + $gapicClient->testIamPermissions($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createAppConnectorAsyncTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/createAppConnectorTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $displayName = 'displayName1615086568'; + $uid = 'uid115792'; + $expectedResponse = new AppConnector(); + $expectedResponse->setName($name); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setUid($uid); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createAppConnectorTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $appConnector = new AppConnector(); + $appConnectorName = 'appConnectorName-1263736873'; + $appConnector->setName($appConnectorName); + $appConnectorPrincipalInfo = new PrincipalInfo(); + $appConnector->setPrincipalInfo($appConnectorPrincipalInfo); + $request = (new CreateAppConnectorRequest()) + ->setParent($formattedParent) + ->setAppConnector($appConnector); + $response = $gapicClient->createAppConnectorAsync($request)->wait(); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.beyondcorp.appconnectors.v1.AppConnectorsService/CreateAppConnector', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getAppConnector(); + $this->assertProtobufEquals($appConnector, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createAppConnectorTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } +} diff --git a/BeyondCorpAppGateways/samples/V1/AppGatewaysServiceClient/create_app_gateway.php b/BeyondCorpAppGateways/samples/V1/AppGatewaysServiceClient/create_app_gateway.php index 1d12cbf420a2..4b72dae2fbf9 100644 --- a/BeyondCorpAppGateways/samples/V1/AppGatewaysServiceClient/create_app_gateway.php +++ b/BeyondCorpAppGateways/samples/V1/AppGatewaysServiceClient/create_app_gateway.php @@ -28,7 +28,8 @@ use Google\Cloud\BeyondCorp\AppGateways\V1\AppGateway; use Google\Cloud\BeyondCorp\AppGateways\V1\AppGateway\HostType; use Google\Cloud\BeyondCorp\AppGateways\V1\AppGateway\Type; -use Google\Cloud\BeyondCorp\AppGateways\V1\AppGatewaysServiceClient; +use Google\Cloud\BeyondCorp\AppGateways\V1\Client\AppGatewaysServiceClient; +use Google\Cloud\BeyondCorp\AppGateways\V1\CreateAppGatewayRequest; use Google\Rpc\Status; /** @@ -51,16 +52,19 @@ function create_app_gateway_sample( // Create a client. $appGatewaysServiceClient = new AppGatewaysServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $appGateway = (new AppGateway()) ->setName($appGatewayName) ->setType($appGatewayType) ->setHostType($appGatewayHostType); + $request = (new CreateAppGatewayRequest()) + ->setParent($formattedParent) + ->setAppGateway($appGateway); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $appGatewaysServiceClient->createAppGateway($formattedParent, $appGateway); + $response = $appGatewaysServiceClient->createAppGateway($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/BeyondCorpAppGateways/samples/V1/AppGatewaysServiceClient/delete_app_gateway.php b/BeyondCorpAppGateways/samples/V1/AppGatewaysServiceClient/delete_app_gateway.php index 2f3bc68ae1c8..a543f2934ce2 100644 --- a/BeyondCorpAppGateways/samples/V1/AppGatewaysServiceClient/delete_app_gateway.php +++ b/BeyondCorpAppGateways/samples/V1/AppGatewaysServiceClient/delete_app_gateway.php @@ -25,7 +25,8 @@ // [START beyondcorp_v1_generated_AppGatewaysService_DeleteAppGateway_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\BeyondCorp\AppGateways\V1\AppGatewaysServiceClient; +use Google\Cloud\BeyondCorp\AppGateways\V1\Client\AppGatewaysServiceClient; +use Google\Cloud\BeyondCorp\AppGateways\V1\DeleteAppGatewayRequest; use Google\Rpc\Status; /** @@ -40,10 +41,14 @@ function delete_app_gateway_sample(string $formattedName): void // Create a client. $appGatewaysServiceClient = new AppGatewaysServiceClient(); + // Prepare the request message. + $request = (new DeleteAppGatewayRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $appGatewaysServiceClient->deleteAppGateway($formattedName); + $response = $appGatewaysServiceClient->deleteAppGateway($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/BeyondCorpAppGateways/samples/V1/AppGatewaysServiceClient/get_app_gateway.php b/BeyondCorpAppGateways/samples/V1/AppGatewaysServiceClient/get_app_gateway.php index 6ab8035bc5a6..2259c5dede81 100644 --- a/BeyondCorpAppGateways/samples/V1/AppGatewaysServiceClient/get_app_gateway.php +++ b/BeyondCorpAppGateways/samples/V1/AppGatewaysServiceClient/get_app_gateway.php @@ -25,7 +25,8 @@ // [START beyondcorp_v1_generated_AppGatewaysService_GetAppGateway_sync] use Google\ApiCore\ApiException; use Google\Cloud\BeyondCorp\AppGateways\V1\AppGateway; -use Google\Cloud\BeyondCorp\AppGateways\V1\AppGatewaysServiceClient; +use Google\Cloud\BeyondCorp\AppGateways\V1\Client\AppGatewaysServiceClient; +use Google\Cloud\BeyondCorp\AppGateways\V1\GetAppGatewayRequest; /** * Gets details of a single AppGateway. @@ -39,10 +40,14 @@ function get_app_gateway_sample(string $formattedName): void // Create a client. $appGatewaysServiceClient = new AppGatewaysServiceClient(); + // Prepare the request message. + $request = (new GetAppGatewayRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var AppGateway $response */ - $response = $appGatewaysServiceClient->getAppGateway($formattedName); + $response = $appGatewaysServiceClient->getAppGateway($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BeyondCorpAppGateways/samples/V1/AppGatewaysServiceClient/get_iam_policy.php b/BeyondCorpAppGateways/samples/V1/AppGatewaysServiceClient/get_iam_policy.php index 0692683c499d..e4182baf1496 100644 --- a/BeyondCorpAppGateways/samples/V1/AppGatewaysServiceClient/get_iam_policy.php +++ b/BeyondCorpAppGateways/samples/V1/AppGatewaysServiceClient/get_iam_policy.php @@ -24,7 +24,8 @@ // [START beyondcorp_v1_generated_AppGatewaysService_GetIamPolicy_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BeyondCorp\AppGateways\V1\AppGatewaysServiceClient; +use Google\Cloud\BeyondCorp\AppGateways\V1\Client\AppGatewaysServiceClient; +use Google\Cloud\Iam\V1\GetIamPolicyRequest; use Google\Cloud\Iam\V1\Policy; /** @@ -39,10 +40,14 @@ function get_iam_policy_sample(string $resource): void // Create a client. $appGatewaysServiceClient = new AppGatewaysServiceClient(); + // Prepare the request message. + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + // Call the API and handle any network failures. try { /** @var Policy $response */ - $response = $appGatewaysServiceClient->getIamPolicy($resource); + $response = $appGatewaysServiceClient->getIamPolicy($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BeyondCorpAppGateways/samples/V1/AppGatewaysServiceClient/get_location.php b/BeyondCorpAppGateways/samples/V1/AppGatewaysServiceClient/get_location.php index 95d90c2f59df..ee642ec9305d 100644 --- a/BeyondCorpAppGateways/samples/V1/AppGatewaysServiceClient/get_location.php +++ b/BeyondCorpAppGateways/samples/V1/AppGatewaysServiceClient/get_location.php @@ -24,7 +24,8 @@ // [START beyondcorp_v1_generated_AppGatewaysService_GetLocation_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BeyondCorp\AppGateways\V1\AppGatewaysServiceClient; +use Google\Cloud\BeyondCorp\AppGateways\V1\Client\AppGatewaysServiceClient; +use Google\Cloud\Location\GetLocationRequest; use Google\Cloud\Location\Location; /** @@ -41,10 +42,13 @@ function get_location_sample(): void // Create a client. $appGatewaysServiceClient = new AppGatewaysServiceClient(); + // Prepare the request message. + $request = new GetLocationRequest(); + // Call the API and handle any network failures. try { /** @var Location $response */ - $response = $appGatewaysServiceClient->getLocation(); + $response = $appGatewaysServiceClient->getLocation($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BeyondCorpAppGateways/samples/V1/AppGatewaysServiceClient/list_app_gateways.php b/BeyondCorpAppGateways/samples/V1/AppGatewaysServiceClient/list_app_gateways.php index 4977a31f190c..19e873c5adcf 100644 --- a/BeyondCorpAppGateways/samples/V1/AppGatewaysServiceClient/list_app_gateways.php +++ b/BeyondCorpAppGateways/samples/V1/AppGatewaysServiceClient/list_app_gateways.php @@ -26,7 +26,8 @@ use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; use Google\Cloud\BeyondCorp\AppGateways\V1\AppGateway; -use Google\Cloud\BeyondCorp\AppGateways\V1\AppGatewaysServiceClient; +use Google\Cloud\BeyondCorp\AppGateways\V1\Client\AppGatewaysServiceClient; +use Google\Cloud\BeyondCorp\AppGateways\V1\ListAppGatewaysRequest; /** * Lists AppGateways in a given project and location. @@ -40,10 +41,14 @@ function list_app_gateways_sample(string $formattedParent): void // Create a client. $appGatewaysServiceClient = new AppGatewaysServiceClient(); + // Prepare the request message. + $request = (new ListAppGatewaysRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $appGatewaysServiceClient->listAppGateways($formattedParent); + $response = $appGatewaysServiceClient->listAppGateways($request); /** @var AppGateway $element */ foreach ($response as $element) { diff --git a/BeyondCorpAppGateways/samples/V1/AppGatewaysServiceClient/list_locations.php b/BeyondCorpAppGateways/samples/V1/AppGatewaysServiceClient/list_locations.php index c7c32844cbf3..5cc04ee4f650 100644 --- a/BeyondCorpAppGateways/samples/V1/AppGatewaysServiceClient/list_locations.php +++ b/BeyondCorpAppGateways/samples/V1/AppGatewaysServiceClient/list_locations.php @@ -25,7 +25,8 @@ // [START beyondcorp_v1_generated_AppGatewaysService_ListLocations_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; -use Google\Cloud\BeyondCorp\AppGateways\V1\AppGatewaysServiceClient; +use Google\Cloud\BeyondCorp\AppGateways\V1\Client\AppGatewaysServiceClient; +use Google\Cloud\Location\ListLocationsRequest; use Google\Cloud\Location\Location; /** @@ -42,10 +43,13 @@ function list_locations_sample(): void // Create a client. $appGatewaysServiceClient = new AppGatewaysServiceClient(); + // Prepare the request message. + $request = new ListLocationsRequest(); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $appGatewaysServiceClient->listLocations(); + $response = $appGatewaysServiceClient->listLocations($request); /** @var Location $element */ foreach ($response as $element) { diff --git a/BeyondCorpAppGateways/samples/V1/AppGatewaysServiceClient/set_iam_policy.php b/BeyondCorpAppGateways/samples/V1/AppGatewaysServiceClient/set_iam_policy.php index 0203e41aa6ec..064ad3404c36 100644 --- a/BeyondCorpAppGateways/samples/V1/AppGatewaysServiceClient/set_iam_policy.php +++ b/BeyondCorpAppGateways/samples/V1/AppGatewaysServiceClient/set_iam_policy.php @@ -24,8 +24,9 @@ // [START beyondcorp_v1_generated_AppGatewaysService_SetIamPolicy_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BeyondCorp\AppGateways\V1\AppGatewaysServiceClient; +use Google\Cloud\BeyondCorp\AppGateways\V1\Client\AppGatewaysServiceClient; use Google\Cloud\Iam\V1\Policy; +use Google\Cloud\Iam\V1\SetIamPolicyRequest; /** * Sets the access control policy on the specified resource. Replaces @@ -42,13 +43,16 @@ function set_iam_policy_sample(string $resource): void // Create a client. $appGatewaysServiceClient = new AppGatewaysServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $policy = new Policy(); + $request = (new SetIamPolicyRequest()) + ->setResource($resource) + ->setPolicy($policy); // Call the API and handle any network failures. try { /** @var Policy $response */ - $response = $appGatewaysServiceClient->setIamPolicy($resource, $policy); + $response = $appGatewaysServiceClient->setIamPolicy($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BeyondCorpAppGateways/samples/V1/AppGatewaysServiceClient/test_iam_permissions.php b/BeyondCorpAppGateways/samples/V1/AppGatewaysServiceClient/test_iam_permissions.php index 74a280917a53..579149af0387 100644 --- a/BeyondCorpAppGateways/samples/V1/AppGatewaysServiceClient/test_iam_permissions.php +++ b/BeyondCorpAppGateways/samples/V1/AppGatewaysServiceClient/test_iam_permissions.php @@ -24,7 +24,8 @@ // [START beyondcorp_v1_generated_AppGatewaysService_TestIamPermissions_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BeyondCorp\AppGateways\V1\AppGatewaysServiceClient; +use Google\Cloud\BeyondCorp\AppGateways\V1\Client\AppGatewaysServiceClient; +use Google\Cloud\Iam\V1\TestIamPermissionsRequest; use Google\Cloud\Iam\V1\TestIamPermissionsResponse; /** @@ -48,13 +49,16 @@ function test_iam_permissions_sample(string $resource, string $permissionsElemen // Create a client. $appGatewaysServiceClient = new AppGatewaysServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $permissions = [$permissionsElement,]; + $request = (new TestIamPermissionsRequest()) + ->setResource($resource) + ->setPermissions($permissions); // Call the API and handle any network failures. try { /** @var TestIamPermissionsResponse $response */ - $response = $appGatewaysServiceClient->testIamPermissions($resource, $permissions); + $response = $appGatewaysServiceClient->testIamPermissions($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BeyondCorpAppGateways/src/V1/Client/AppGatewaysServiceClient.php b/BeyondCorpAppGateways/src/V1/Client/AppGatewaysServiceClient.php new file mode 100644 index 000000000000..fa2c2ae0a784 --- /dev/null +++ b/BeyondCorpAppGateways/src/V1/Client/AppGatewaysServiceClient.php @@ -0,0 +1,40 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/app_gateways_service_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/app_gateways_service_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/app_gateways_service_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/app_gateways_service_rest_client_config.php', + ], + ], + ]; + } + + /** + * Return an OperationsClient object with the same endpoint as $this. + * + * @return OperationsClient + */ + public function getOperationsClient() + { + return $this->operationsClient; + } + + /** + * Resume an existing long running operation that was previously started by a long + * running API method. If $methodName is not provided, or does not match a long + * running API method, then the operation can still be resumed, but the + * OperationResponse object will not deserialize the final response. + * + * @param string $operationName The name of the long running operation + * @param string $methodName The name of the method used to start the operation + * + * @return OperationResponse + */ + public function resumeOperation($operationName, $methodName = null) + { + $options = isset($this->descriptors[$methodName]['longRunning']) ? $this->descriptors[$methodName]['longRunning'] : []; + $operation = new OperationResponse($operationName, $this->getOperationsClient(), $options); + $operation->reload(); + return $operation; + } + + /** + * Formats a string containing the fully-qualified path to represent a app_gateway + * resource. + * + * @param string $project + * @param string $location + * @param string $appGateway + * + * @return string The formatted app_gateway resource. + */ + public static function appGatewayName(string $project, string $location, string $appGateway): string + { + return self::getPathTemplate('appGateway')->render([ + 'project' => $project, + 'location' => $location, + 'app_gateway' => $appGateway, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a location + * resource. + * + * @param string $project + * @param string $location + * + * @return string The formatted location resource. + */ + public static function locationName(string $project, string $location): string + { + return self::getPathTemplate('location')->render([ + 'project' => $project, + 'location' => $location, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * Template: Pattern + * - appGateway: projects/{project}/locations/{location}/appGateways/{app_gateway} + * - location: projects/{project}/locations/{location} + * + * The optional $template argument can be supplied to specify a particular pattern, + * and must match one of the templates listed above. If no $template argument is + * provided, or if the $template argument does not match one of the templates + * listed, then parseName will check each of the supported templates, and return + * the first match. + * + * @param string $formattedName The formatted name string + * @param string $template Optional name of template to match + * + * @return array An associative array from name component IDs to component values. + * + * @throws ValidationException If $formattedName could not be matched. + */ + public static function parseName(string $formattedName, string $template = null): array + { + return self::parseFormattedName($formattedName, $template); + } + + /** + * Constructor. + * + * @param array $options { + * Optional. Options for configuring the service API wrapper. + * + * @type string $apiEndpoint + * The address of the API remote host. May optionally include the port, formatted + * as ":". Default 'beyondcorp.googleapis.com:443'. + * @type string|array|FetchAuthTokenInterface|CredentialsWrapper $credentials + * The credentials to be used by the client to authorize API calls. This option + * accepts either a path to a credentials file, or a decoded credentials file as a + * PHP array. + * *Advanced usage*: In addition, this option can also accept a pre-constructed + * {@see \Google\Auth\FetchAuthTokenInterface} object or + * {@see \Google\ApiCore\CredentialsWrapper} object. Note that when one of these + * objects are provided, any settings in $credentialsConfig will be ignored. + * @type array $credentialsConfig + * Options used to configure credentials, including auth token caching, for the + * client. For a full list of supporting configuration options, see + * {@see \Google\ApiCore\CredentialsWrapper::build()} . + * @type bool $disableRetries + * Determines whether or not retries defined by the client configuration should be + * disabled. Defaults to `false`. + * @type string|array $clientConfig + * Client method configuration, including retry settings. This option can be either + * a path to a JSON file, or a PHP array containing the decoded JSON data. By + * default this settings points to the default client config file, which is + * provided in the resources folder. + * @type string|TransportInterface $transport + * The transport used for executing network requests. May be either the string + * `rest` or `grpc`. Defaults to `grpc` if gRPC support is detected on the system. + * *Advanced usage*: Additionally, it is possible to pass in an already + * instantiated {@see \Google\ApiCore\Transport\TransportInterface} object. Note + * that when this object is provided, any settings in $transportConfig, and any + * $apiEndpoint setting, will be ignored. + * @type array $transportConfig + * Configuration options that will be used to construct the transport. Options for + * each supported transport type should be passed in a key for that transport. For + * example: + * $transportConfig = [ + * 'grpc' => [...], + * 'rest' => [...], + * ]; + * See the {@see \Google\ApiCore\Transport\GrpcTransport::build()} and + * {@see \Google\ApiCore\Transport\RestTransport::build()} methods for the + * supported options. + * @type callable $clientCertSource + * A callable which returns the client cert as a string. This can be used to + * provide a certificate and private key to the transport layer for mTLS. + * } + * + * @throws ValidationException + */ + public function __construct(array $options = []) + { + $clientOptions = $this->buildClientOptions($options); + $this->setClientOptions($clientOptions); + $this->operationsClient = $this->createOperationsClient($clientOptions); + } + + /** Handles execution of the async variants for each documented method. */ + public function __call($method, $args) + { + if (substr($method, -5) !== 'Async') { + trigger_error('Call to undefined method ' . __CLASS__ . "::$method()", E_USER_ERROR); + } + + array_unshift($args, substr($method, 0, -5)); + return call_user_func_array([$this, 'startAsyncCall'], $args); + } + + /** + * Creates a new AppGateway in a given project and location. + * + * The async variant is {@see self::createAppGatewayAsync()} . + * + * @param CreateAppGatewayRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function createAppGateway(CreateAppGatewayRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('CreateAppGateway', $request, $callOptions)->wait(); + } + + /** + * Deletes a single AppGateway. + * + * The async variant is {@see self::deleteAppGatewayAsync()} . + * + * @param DeleteAppGatewayRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function deleteAppGateway(DeleteAppGatewayRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('DeleteAppGateway', $request, $callOptions)->wait(); + } + + /** + * Gets details of a single AppGateway. + * + * The async variant is {@see self::getAppGatewayAsync()} . + * + * @param GetAppGatewayRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return AppGateway + * + * @throws ApiException Thrown if the API call fails. + */ + public function getAppGateway(GetAppGatewayRequest $request, array $callOptions = []): AppGateway + { + return $this->startApiCall('GetAppGateway', $request, $callOptions)->wait(); + } + + /** + * Lists AppGateways in a given project and location. + * + * The async variant is {@see self::listAppGatewaysAsync()} . + * + * @param ListAppGatewaysRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listAppGateways(ListAppGatewaysRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListAppGateways', $request, $callOptions); + } + + /** + * Gets information about a location. + * + * The async variant is {@see self::getLocationAsync()} . + * + * @param GetLocationRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Location + * + * @throws ApiException Thrown if the API call fails. + */ + public function getLocation(GetLocationRequest $request, array $callOptions = []): Location + { + return $this->startApiCall('GetLocation', $request, $callOptions)->wait(); + } + + /** + * Lists information about the supported locations for this service. + * + * The async variant is {@see self::listLocationsAsync()} . + * + * @param ListLocationsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listLocations(ListLocationsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListLocations', $request, $callOptions); + } + + /** + * Gets the access control policy for a resource. Returns an empty policy + if the resource exists and does not have a policy set. + * + * The async variant is {@see self::getIamPolicyAsync()} . + * + * @param GetIamPolicyRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Policy + * + * @throws ApiException Thrown if the API call fails. + */ + public function getIamPolicy(GetIamPolicyRequest $request, array $callOptions = []): Policy + { + return $this->startApiCall('GetIamPolicy', $request, $callOptions)->wait(); + } + + /** + * Sets the access control policy on the specified resource. Replaces + any existing policy. + + Can return `NOT_FOUND`, `INVALID_ARGUMENT`, and `PERMISSION_DENIED` + errors. + * + * The async variant is {@see self::setIamPolicyAsync()} . + * + * @param SetIamPolicyRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Policy + * + * @throws ApiException Thrown if the API call fails. + */ + public function setIamPolicy(SetIamPolicyRequest $request, array $callOptions = []): Policy + { + return $this->startApiCall('SetIamPolicy', $request, $callOptions)->wait(); + } + + /** + * Returns permissions that a caller has on the specified resource. If the + resource does not exist, this will return an empty set of + permissions, not a `NOT_FOUND` error. + + Note: This operation is designed to be used for building + permission-aware UIs and command-line tools, not for authorization + checking. This operation may "fail open" without warning. + * + * The async variant is {@see self::testIamPermissionsAsync()} . + * + * @param TestIamPermissionsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return TestIamPermissionsResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function testIamPermissions(TestIamPermissionsRequest $request, array $callOptions = []): TestIamPermissionsResponse + { + return $this->startApiCall('TestIamPermissions', $request, $callOptions)->wait(); + } +} diff --git a/BeyondCorpAppGateways/src/V1/CreateAppGatewayRequest.php b/BeyondCorpAppGateways/src/V1/CreateAppGatewayRequest.php index 07bdd12880d9..7cdb4f5bb709 100644 --- a/BeyondCorpAppGateways/src/V1/CreateAppGatewayRequest.php +++ b/BeyondCorpAppGateways/src/V1/CreateAppGatewayRequest.php @@ -61,6 +61,28 @@ class CreateAppGatewayRequest extends \Google\Protobuf\Internal\Message */ private $validate_only = false; + /** + * @param string $parent Required. The resource project name of the AppGateway location using the + * form: `projects/{project_id}/locations/{location_id}` + * Please see {@see AppGatewaysServiceClient::locationName()} for help formatting this field. + * @param \Google\Cloud\BeyondCorp\AppGateways\V1\AppGateway $appGateway Required. A BeyondCorp AppGateway resource. + * @param string $appGatewayId Optional. User-settable AppGateway resource ID. + * * Must start with a letter. + * * Must contain between 4-63 characters from `/[a-z][0-9]-/`. + * * Must end with a number or a letter. + * + * @return \Google\Cloud\BeyondCorp\AppGateways\V1\CreateAppGatewayRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\BeyondCorp\AppGateways\V1\AppGateway $appGateway, string $appGatewayId): self + { + return (new self()) + ->setParent($parent) + ->setAppGateway($appGateway) + ->setAppGatewayId($appGatewayId); + } + /** * Constructor. * diff --git a/BeyondCorpAppGateways/src/V1/DeleteAppGatewayRequest.php b/BeyondCorpAppGateways/src/V1/DeleteAppGatewayRequest.php index bb38ea8520ef..12f8ed7be02e 100644 --- a/BeyondCorpAppGateways/src/V1/DeleteAppGatewayRequest.php +++ b/BeyondCorpAppGateways/src/V1/DeleteAppGatewayRequest.php @@ -46,6 +46,21 @@ class DeleteAppGatewayRequest extends \Google\Protobuf\Internal\Message */ private $validate_only = false; + /** + * @param string $name Required. BeyondCorp AppGateway name using the form: + * `projects/{project_id}/locations/{location_id}/appGateways/{app_gateway_id}` + * Please see {@see AppGatewaysServiceClient::appGatewayName()} for help formatting this field. + * + * @return \Google\Cloud\BeyondCorp\AppGateways\V1\DeleteAppGatewayRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/BeyondCorpAppGateways/src/V1/GetAppGatewayRequest.php b/BeyondCorpAppGateways/src/V1/GetAppGatewayRequest.php index 20b715f77585..829a72acb3cb 100644 --- a/BeyondCorpAppGateways/src/V1/GetAppGatewayRequest.php +++ b/BeyondCorpAppGateways/src/V1/GetAppGatewayRequest.php @@ -23,6 +23,21 @@ class GetAppGatewayRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. BeyondCorp AppGateway name using the form: + * `projects/{project_id}/locations/{location_id}/appGateways/{app_gateway_id}` + * Please see {@see AppGatewaysServiceClient::appGatewayName()} for help formatting this field. + * + * @return \Google\Cloud\BeyondCorp\AppGateways\V1\GetAppGatewayRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/BeyondCorpAppGateways/src/V1/ListAppGatewaysRequest.php b/BeyondCorpAppGateways/src/V1/ListAppGatewaysRequest.php index 8c7bcbd11493..751049db5960 100644 --- a/BeyondCorpAppGateways/src/V1/ListAppGatewaysRequest.php +++ b/BeyondCorpAppGateways/src/V1/ListAppGatewaysRequest.php @@ -56,6 +56,21 @@ class ListAppGatewaysRequest extends \Google\Protobuf\Internal\Message */ private $order_by = ''; + /** + * @param string $parent Required. The resource name of the AppGateway location using the form: + * `projects/{project_id}/locations/{location_id}` + * Please see {@see AppGatewaysServiceClient::locationName()} for help formatting this field. + * + * @return \Google\Cloud\BeyondCorp\AppGateways\V1\ListAppGatewaysRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/BeyondCorpAppGateways/src/V1/resources/app_gateways_service_descriptor_config.php b/BeyondCorpAppGateways/src/V1/resources/app_gateways_service_descriptor_config.php index f49bc450817d..270c9a8fe5da 100644 --- a/BeyondCorpAppGateways/src/V1/resources/app_gateways_service_descriptor_config.php +++ b/BeyondCorpAppGateways/src/V1/resources/app_gateways_service_descriptor_config.php @@ -12,6 +12,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'DeleteAppGateway' => [ 'longRunning' => [ @@ -22,6 +31,27 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetAppGateway' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\BeyondCorp\AppGateways\V1\AppGateway', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'ListAppGateways' => [ 'pageStreaming' => [ @@ -32,8 +62,28 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getAppGateways', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\BeyondCorp\AppGateways\V1\ListAppGatewaysResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'GetLocation' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Location\Location', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], 'interfaceOverride' => 'google.cloud.location.Locations', ], 'ListLocations' => [ @@ -45,17 +95,61 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getLocations', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\Location\ListLocationsResponse', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], 'interfaceOverride' => 'google.cloud.location.Locations', ], 'GetIamPolicy' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\Policy', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], 'interfaceOverride' => 'google.iam.v1.IAMPolicy', ], 'SetIamPolicy' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\Policy', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], 'interfaceOverride' => 'google.iam.v1.IAMPolicy', ], 'TestIamPermissions' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\TestIamPermissionsResponse', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], 'interfaceOverride' => 'google.iam.v1.IAMPolicy', ], + 'templateMap' => [ + 'appGateway' => 'projects/{project}/locations/{location}/appGateways/{app_gateway}', + 'location' => 'projects/{project}/locations/{location}', + ], ], ], ]; diff --git a/BeyondCorpAppGateways/tests/Unit/V1/Client/AppGatewaysServiceClientTest.php b/BeyondCorpAppGateways/tests/Unit/V1/Client/AppGatewaysServiceClientTest.php new file mode 100644 index 000000000000..7155d2dc2ace --- /dev/null +++ b/BeyondCorpAppGateways/tests/Unit/V1/Client/AppGatewaysServiceClientTest.php @@ -0,0 +1,904 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return AppGatewaysServiceClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new AppGatewaysServiceClient($options); + } + + /** @test */ + public function createAppGatewayTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/createAppGatewayTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $displayName = 'displayName1615086568'; + $uid = 'uid115792'; + $uri = 'uri116076'; + $expectedResponse = new AppGateway(); + $expectedResponse->setName($name); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setUid($uid); + $expectedResponse->setUri($uri); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createAppGatewayTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $appGateway = new AppGateway(); + $appGatewayName = 'appGatewayName-1786203634'; + $appGateway->setName($appGatewayName); + $appGatewayType = Type::TYPE_UNSPECIFIED; + $appGateway->setType($appGatewayType); + $appGatewayHostType = HostType::HOST_TYPE_UNSPECIFIED; + $appGateway->setHostType($appGatewayHostType); + $request = (new CreateAppGatewayRequest()) + ->setParent($formattedParent) + ->setAppGateway($appGateway); + $response = $gapicClient->createAppGateway($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.beyondcorp.appgateways.v1.AppGatewaysService/CreateAppGateway', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getAppGateway(); + $this->assertProtobufEquals($appGateway, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createAppGatewayTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function createAppGatewayExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/createAppGatewayTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $appGateway = new AppGateway(); + $appGatewayName = 'appGatewayName-1786203634'; + $appGateway->setName($appGatewayName); + $appGatewayType = Type::TYPE_UNSPECIFIED; + $appGateway->setType($appGatewayType); + $appGatewayHostType = HostType::HOST_TYPE_UNSPECIFIED; + $appGateway->setHostType($appGatewayHostType); + $request = (new CreateAppGatewayRequest()) + ->setParent($formattedParent) + ->setAppGateway($appGateway); + $response = $gapicClient->createAppGateway($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createAppGatewayTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function deleteAppGatewayTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/deleteAppGatewayTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new GPBEmpty(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/deleteAppGatewayTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->appGatewayName('[PROJECT]', '[LOCATION]', '[APP_GATEWAY]'); + $request = (new DeleteAppGatewayRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteAppGateway($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.beyondcorp.appgateways.v1.AppGatewaysService/DeleteAppGateway', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteAppGatewayTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function deleteAppGatewayExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/deleteAppGatewayTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->appGatewayName('[PROJECT]', '[LOCATION]', '[APP_GATEWAY]'); + $request = (new DeleteAppGatewayRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteAppGateway($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteAppGatewayTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function getAppGatewayTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $displayName = 'displayName1615086568'; + $uid = 'uid115792'; + $uri = 'uri116076'; + $expectedResponse = new AppGateway(); + $expectedResponse->setName($name2); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setUid($uid); + $expectedResponse->setUri($uri); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->appGatewayName('[PROJECT]', '[LOCATION]', '[APP_GATEWAY]'); + $request = (new GetAppGatewayRequest()) + ->setName($formattedName); + $response = $gapicClient->getAppGateway($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.beyondcorp.appgateways.v1.AppGatewaysService/GetAppGateway', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getAppGatewayExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->appGatewayName('[PROJECT]', '[LOCATION]', '[APP_GATEWAY]'); + $request = (new GetAppGatewayRequest()) + ->setName($formattedName); + try { + $gapicClient->getAppGateway($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listAppGatewaysTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $appGatewaysElement = new AppGateway(); + $appGateways = [ + $appGatewaysElement, + ]; + $expectedResponse = new ListAppGatewaysResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setAppGateways($appGateways); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListAppGatewaysRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listAppGateways($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getAppGateways()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.beyondcorp.appgateways.v1.AppGatewaysService/ListAppGateways', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listAppGatewaysExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListAppGatewaysRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listAppGateways($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getLocationTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $locationId = 'locationId552319461'; + $displayName = 'displayName1615086568'; + $expectedResponse = new Location(); + $expectedResponse->setName($name2); + $expectedResponse->setLocationId($locationId); + $expectedResponse->setDisplayName($displayName); + $transport->addResponse($expectedResponse); + $request = new GetLocationRequest(); + $response = $gapicClient->getLocation($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.location.Locations/GetLocation', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getLocationExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + $request = new GetLocationRequest(); + try { + $gapicClient->getLocation($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listLocationsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $locationsElement = new Location(); + $locations = [ + $locationsElement, + ]; + $expectedResponse = new ListLocationsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setLocations($locations); + $transport->addResponse($expectedResponse); + $request = new ListLocationsRequest(); + $response = $gapicClient->listLocations($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getLocations()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.location.Locations/ListLocations', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listLocationsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + $request = new ListLocationsRequest(); + try { + $gapicClient->listLocations($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getIamPolicyTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $version = 351608024; + $etag = '21'; + $expectedResponse = new Policy(); + $expectedResponse->setVersion($version); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + $response = $gapicClient->getIamPolicy($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.iam.v1.IAMPolicy/GetIamPolicy', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getIamPolicyExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $resource = 'resource-341064690'; + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + try { + $gapicClient->getIamPolicy($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function setIamPolicyTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $version = 351608024; + $etag = '21'; + $expectedResponse = new Policy(); + $expectedResponse->setVersion($version); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $policy = new Policy(); + $request = (new SetIamPolicyRequest()) + ->setResource($resource) + ->setPolicy($policy); + $response = $gapicClient->setIamPolicy($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.iam.v1.IAMPolicy/SetIamPolicy', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $actualValue = $actualRequestObject->getPolicy(); + $this->assertProtobufEquals($policy, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function setIamPolicyExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $resource = 'resource-341064690'; + $policy = new Policy(); + $request = (new SetIamPolicyRequest()) + ->setResource($resource) + ->setPolicy($policy); + try { + $gapicClient->setIamPolicy($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function testIamPermissionsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new TestIamPermissionsResponse(); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $permissions = []; + $request = (new TestIamPermissionsRequest()) + ->setResource($resource) + ->setPermissions($permissions); + $response = $gapicClient->testIamPermissions($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.iam.v1.IAMPolicy/TestIamPermissions', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $actualValue = $actualRequestObject->getPermissions(); + $this->assertProtobufEquals($permissions, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function testIamPermissionsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $resource = 'resource-341064690'; + $permissions = []; + $request = (new TestIamPermissionsRequest()) + ->setResource($resource) + ->setPermissions($permissions); + try { + $gapicClient->testIamPermissions($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createAppGatewayAsyncTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/createAppGatewayTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $displayName = 'displayName1615086568'; + $uid = 'uid115792'; + $uri = 'uri116076'; + $expectedResponse = new AppGateway(); + $expectedResponse->setName($name); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setUid($uid); + $expectedResponse->setUri($uri); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createAppGatewayTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $appGateway = new AppGateway(); + $appGatewayName = 'appGatewayName-1786203634'; + $appGateway->setName($appGatewayName); + $appGatewayType = Type::TYPE_UNSPECIFIED; + $appGateway->setType($appGatewayType); + $appGatewayHostType = HostType::HOST_TYPE_UNSPECIFIED; + $appGateway->setHostType($appGatewayHostType); + $request = (new CreateAppGatewayRequest()) + ->setParent($formattedParent) + ->setAppGateway($appGateway); + $response = $gapicClient->createAppGatewayAsync($request)->wait(); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.beyondcorp.appgateways.v1.AppGatewaysService/CreateAppGateway', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getAppGateway(); + $this->assertProtobufEquals($appGateway, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createAppGatewayTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } +} diff --git a/BeyondCorpClientConnectorServices/samples/V1/ClientConnectorServicesServiceClient/create_client_connector_service.php b/BeyondCorpClientConnectorServices/samples/V1/ClientConnectorServicesServiceClient/create_client_connector_service.php index 59c73322f006..bf80bd33f586 100644 --- a/BeyondCorpClientConnectorServices/samples/V1/ClientConnectorServicesServiceClient/create_client_connector_service.php +++ b/BeyondCorpClientConnectorServices/samples/V1/ClientConnectorServicesServiceClient/create_client_connector_service.php @@ -28,7 +28,8 @@ use Google\Cloud\BeyondCorp\ClientConnectorServices\V1\ClientConnectorService; use Google\Cloud\BeyondCorp\ClientConnectorServices\V1\ClientConnectorService\Egress; use Google\Cloud\BeyondCorp\ClientConnectorServices\V1\ClientConnectorService\Ingress; -use Google\Cloud\BeyondCorp\ClientConnectorServices\V1\ClientConnectorServicesServiceClient; +use Google\Cloud\BeyondCorp\ClientConnectorServices\V1\Client\ClientConnectorServicesServiceClient; +use Google\Cloud\BeyondCorp\ClientConnectorServices\V1\CreateClientConnectorServiceRequest; use Google\Rpc\Status; /** @@ -45,21 +46,21 @@ function create_client_connector_service_sample( // Create a client. $clientConnectorServicesServiceClient = new ClientConnectorServicesServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $clientConnectorServiceIngress = new Ingress(); $clientConnectorServiceEgress = new Egress(); $clientConnectorService = (new ClientConnectorService()) ->setName($clientConnectorServiceName) ->setIngress($clientConnectorServiceIngress) ->setEgress($clientConnectorServiceEgress); + $request = (new CreateClientConnectorServiceRequest()) + ->setParent($formattedParent) + ->setClientConnectorService($clientConnectorService); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $clientConnectorServicesServiceClient->createClientConnectorService( - $formattedParent, - $clientConnectorService - ); + $response = $clientConnectorServicesServiceClient->createClientConnectorService($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/BeyondCorpClientConnectorServices/samples/V1/ClientConnectorServicesServiceClient/delete_client_connector_service.php b/BeyondCorpClientConnectorServices/samples/V1/ClientConnectorServicesServiceClient/delete_client_connector_service.php index 9d51c0a06711..df7d34e8d718 100644 --- a/BeyondCorpClientConnectorServices/samples/V1/ClientConnectorServicesServiceClient/delete_client_connector_service.php +++ b/BeyondCorpClientConnectorServices/samples/V1/ClientConnectorServicesServiceClient/delete_client_connector_service.php @@ -25,7 +25,8 @@ // [START beyondcorp_v1_generated_ClientConnectorServicesService_DeleteClientConnectorService_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\BeyondCorp\ClientConnectorServices\V1\ClientConnectorServicesServiceClient; +use Google\Cloud\BeyondCorp\ClientConnectorServices\V1\Client\ClientConnectorServicesServiceClient; +use Google\Cloud\BeyondCorp\ClientConnectorServices\V1\DeleteClientConnectorServiceRequest; use Google\Rpc\Status; /** @@ -39,10 +40,14 @@ function delete_client_connector_service_sample(string $formattedName): void // Create a client. $clientConnectorServicesServiceClient = new ClientConnectorServicesServiceClient(); + // Prepare the request message. + $request = (new DeleteClientConnectorServiceRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $clientConnectorServicesServiceClient->deleteClientConnectorService($formattedName); + $response = $clientConnectorServicesServiceClient->deleteClientConnectorService($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/BeyondCorpClientConnectorServices/samples/V1/ClientConnectorServicesServiceClient/get_client_connector_service.php b/BeyondCorpClientConnectorServices/samples/V1/ClientConnectorServicesServiceClient/get_client_connector_service.php index 97d61cf288b4..7f2adcc6cb9d 100644 --- a/BeyondCorpClientConnectorServices/samples/V1/ClientConnectorServicesServiceClient/get_client_connector_service.php +++ b/BeyondCorpClientConnectorServices/samples/V1/ClientConnectorServicesServiceClient/get_client_connector_service.php @@ -25,7 +25,8 @@ // [START beyondcorp_v1_generated_ClientConnectorServicesService_GetClientConnectorService_sync] use Google\ApiCore\ApiException; use Google\Cloud\BeyondCorp\ClientConnectorServices\V1\ClientConnectorService; -use Google\Cloud\BeyondCorp\ClientConnectorServices\V1\ClientConnectorServicesServiceClient; +use Google\Cloud\BeyondCorp\ClientConnectorServices\V1\Client\ClientConnectorServicesServiceClient; +use Google\Cloud\BeyondCorp\ClientConnectorServices\V1\GetClientConnectorServiceRequest; /** * Gets details of a single ClientConnectorService. @@ -38,10 +39,14 @@ function get_client_connector_service_sample(string $formattedName): void // Create a client. $clientConnectorServicesServiceClient = new ClientConnectorServicesServiceClient(); + // Prepare the request message. + $request = (new GetClientConnectorServiceRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var ClientConnectorService $response */ - $response = $clientConnectorServicesServiceClient->getClientConnectorService($formattedName); + $response = $clientConnectorServicesServiceClient->getClientConnectorService($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BeyondCorpClientConnectorServices/samples/V1/ClientConnectorServicesServiceClient/get_iam_policy.php b/BeyondCorpClientConnectorServices/samples/V1/ClientConnectorServicesServiceClient/get_iam_policy.php index 995a64383848..488644ac6b2e 100644 --- a/BeyondCorpClientConnectorServices/samples/V1/ClientConnectorServicesServiceClient/get_iam_policy.php +++ b/BeyondCorpClientConnectorServices/samples/V1/ClientConnectorServicesServiceClient/get_iam_policy.php @@ -24,7 +24,8 @@ // [START beyondcorp_v1_generated_ClientConnectorServicesService_GetIamPolicy_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BeyondCorp\ClientConnectorServices\V1\ClientConnectorServicesServiceClient; +use Google\Cloud\BeyondCorp\ClientConnectorServices\V1\Client\ClientConnectorServicesServiceClient; +use Google\Cloud\Iam\V1\GetIamPolicyRequest; use Google\Cloud\Iam\V1\Policy; /** @@ -39,10 +40,14 @@ function get_iam_policy_sample(string $resource): void // Create a client. $clientConnectorServicesServiceClient = new ClientConnectorServicesServiceClient(); + // Prepare the request message. + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + // Call the API and handle any network failures. try { /** @var Policy $response */ - $response = $clientConnectorServicesServiceClient->getIamPolicy($resource); + $response = $clientConnectorServicesServiceClient->getIamPolicy($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BeyondCorpClientConnectorServices/samples/V1/ClientConnectorServicesServiceClient/get_location.php b/BeyondCorpClientConnectorServices/samples/V1/ClientConnectorServicesServiceClient/get_location.php index 213d17e0dae1..7b7e2d64f08b 100644 --- a/BeyondCorpClientConnectorServices/samples/V1/ClientConnectorServicesServiceClient/get_location.php +++ b/BeyondCorpClientConnectorServices/samples/V1/ClientConnectorServicesServiceClient/get_location.php @@ -24,7 +24,8 @@ // [START beyondcorp_v1_generated_ClientConnectorServicesService_GetLocation_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BeyondCorp\ClientConnectorServices\V1\ClientConnectorServicesServiceClient; +use Google\Cloud\BeyondCorp\ClientConnectorServices\V1\Client\ClientConnectorServicesServiceClient; +use Google\Cloud\Location\GetLocationRequest; use Google\Cloud\Location\Location; /** @@ -41,10 +42,13 @@ function get_location_sample(): void // Create a client. $clientConnectorServicesServiceClient = new ClientConnectorServicesServiceClient(); + // Prepare the request message. + $request = new GetLocationRequest(); + // Call the API and handle any network failures. try { /** @var Location $response */ - $response = $clientConnectorServicesServiceClient->getLocation(); + $response = $clientConnectorServicesServiceClient->getLocation($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BeyondCorpClientConnectorServices/samples/V1/ClientConnectorServicesServiceClient/list_client_connector_services.php b/BeyondCorpClientConnectorServices/samples/V1/ClientConnectorServicesServiceClient/list_client_connector_services.php index 20fd1faaa2bf..8ac8cf783ffa 100644 --- a/BeyondCorpClientConnectorServices/samples/V1/ClientConnectorServicesServiceClient/list_client_connector_services.php +++ b/BeyondCorpClientConnectorServices/samples/V1/ClientConnectorServicesServiceClient/list_client_connector_services.php @@ -26,7 +26,8 @@ use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; use Google\Cloud\BeyondCorp\ClientConnectorServices\V1\ClientConnectorService; -use Google\Cloud\BeyondCorp\ClientConnectorServices\V1\ClientConnectorServicesServiceClient; +use Google\Cloud\BeyondCorp\ClientConnectorServices\V1\Client\ClientConnectorServicesServiceClient; +use Google\Cloud\BeyondCorp\ClientConnectorServices\V1\ListClientConnectorServicesRequest; /** * Lists ClientConnectorServices in a given project and location. @@ -39,10 +40,14 @@ function list_client_connector_services_sample(string $formattedParent): void // Create a client. $clientConnectorServicesServiceClient = new ClientConnectorServicesServiceClient(); + // Prepare the request message. + $request = (new ListClientConnectorServicesRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $clientConnectorServicesServiceClient->listClientConnectorServices($formattedParent); + $response = $clientConnectorServicesServiceClient->listClientConnectorServices($request); /** @var ClientConnectorService $element */ foreach ($response as $element) { diff --git a/BeyondCorpClientConnectorServices/samples/V1/ClientConnectorServicesServiceClient/list_locations.php b/BeyondCorpClientConnectorServices/samples/V1/ClientConnectorServicesServiceClient/list_locations.php index 728283c2fa02..8107e78c6720 100644 --- a/BeyondCorpClientConnectorServices/samples/V1/ClientConnectorServicesServiceClient/list_locations.php +++ b/BeyondCorpClientConnectorServices/samples/V1/ClientConnectorServicesServiceClient/list_locations.php @@ -25,7 +25,8 @@ // [START beyondcorp_v1_generated_ClientConnectorServicesService_ListLocations_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; -use Google\Cloud\BeyondCorp\ClientConnectorServices\V1\ClientConnectorServicesServiceClient; +use Google\Cloud\BeyondCorp\ClientConnectorServices\V1\Client\ClientConnectorServicesServiceClient; +use Google\Cloud\Location\ListLocationsRequest; use Google\Cloud\Location\Location; /** @@ -42,10 +43,13 @@ function list_locations_sample(): void // Create a client. $clientConnectorServicesServiceClient = new ClientConnectorServicesServiceClient(); + // Prepare the request message. + $request = new ListLocationsRequest(); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $clientConnectorServicesServiceClient->listLocations(); + $response = $clientConnectorServicesServiceClient->listLocations($request); /** @var Location $element */ foreach ($response as $element) { diff --git a/BeyondCorpClientConnectorServices/samples/V1/ClientConnectorServicesServiceClient/set_iam_policy.php b/BeyondCorpClientConnectorServices/samples/V1/ClientConnectorServicesServiceClient/set_iam_policy.php index ff24cc887023..559ce0e96c8f 100644 --- a/BeyondCorpClientConnectorServices/samples/V1/ClientConnectorServicesServiceClient/set_iam_policy.php +++ b/BeyondCorpClientConnectorServices/samples/V1/ClientConnectorServicesServiceClient/set_iam_policy.php @@ -24,8 +24,9 @@ // [START beyondcorp_v1_generated_ClientConnectorServicesService_SetIamPolicy_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BeyondCorp\ClientConnectorServices\V1\ClientConnectorServicesServiceClient; +use Google\Cloud\BeyondCorp\ClientConnectorServices\V1\Client\ClientConnectorServicesServiceClient; use Google\Cloud\Iam\V1\Policy; +use Google\Cloud\Iam\V1\SetIamPolicyRequest; /** * Sets the access control policy on the specified resource. Replaces @@ -42,13 +43,16 @@ function set_iam_policy_sample(string $resource): void // Create a client. $clientConnectorServicesServiceClient = new ClientConnectorServicesServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $policy = new Policy(); + $request = (new SetIamPolicyRequest()) + ->setResource($resource) + ->setPolicy($policy); // Call the API and handle any network failures. try { /** @var Policy $response */ - $response = $clientConnectorServicesServiceClient->setIamPolicy($resource, $policy); + $response = $clientConnectorServicesServiceClient->setIamPolicy($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BeyondCorpClientConnectorServices/samples/V1/ClientConnectorServicesServiceClient/test_iam_permissions.php b/BeyondCorpClientConnectorServices/samples/V1/ClientConnectorServicesServiceClient/test_iam_permissions.php index fb34e335df9b..c0f8e80df712 100644 --- a/BeyondCorpClientConnectorServices/samples/V1/ClientConnectorServicesServiceClient/test_iam_permissions.php +++ b/BeyondCorpClientConnectorServices/samples/V1/ClientConnectorServicesServiceClient/test_iam_permissions.php @@ -24,7 +24,8 @@ // [START beyondcorp_v1_generated_ClientConnectorServicesService_TestIamPermissions_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BeyondCorp\ClientConnectorServices\V1\ClientConnectorServicesServiceClient; +use Google\Cloud\BeyondCorp\ClientConnectorServices\V1\Client\ClientConnectorServicesServiceClient; +use Google\Cloud\Iam\V1\TestIamPermissionsRequest; use Google\Cloud\Iam\V1\TestIamPermissionsResponse; /** @@ -48,13 +49,16 @@ function test_iam_permissions_sample(string $resource, string $permissionsElemen // Create a client. $clientConnectorServicesServiceClient = new ClientConnectorServicesServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $permissions = [$permissionsElement,]; + $request = (new TestIamPermissionsRequest()) + ->setResource($resource) + ->setPermissions($permissions); // Call the API and handle any network failures. try { /** @var TestIamPermissionsResponse $response */ - $response = $clientConnectorServicesServiceClient->testIamPermissions($resource, $permissions); + $response = $clientConnectorServicesServiceClient->testIamPermissions($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BeyondCorpClientConnectorServices/samples/V1/ClientConnectorServicesServiceClient/update_client_connector_service.php b/BeyondCorpClientConnectorServices/samples/V1/ClientConnectorServicesServiceClient/update_client_connector_service.php index aed552bf47d4..96ec12eb14b5 100644 --- a/BeyondCorpClientConnectorServices/samples/V1/ClientConnectorServicesServiceClient/update_client_connector_service.php +++ b/BeyondCorpClientConnectorServices/samples/V1/ClientConnectorServicesServiceClient/update_client_connector_service.php @@ -28,7 +28,8 @@ use Google\Cloud\BeyondCorp\ClientConnectorServices\V1\ClientConnectorService; use Google\Cloud\BeyondCorp\ClientConnectorServices\V1\ClientConnectorService\Egress; use Google\Cloud\BeyondCorp\ClientConnectorServices\V1\ClientConnectorService\Ingress; -use Google\Cloud\BeyondCorp\ClientConnectorServices\V1\ClientConnectorServicesServiceClient; +use Google\Cloud\BeyondCorp\ClientConnectorServices\V1\Client\ClientConnectorServicesServiceClient; +use Google\Cloud\BeyondCorp\ClientConnectorServices\V1\UpdateClientConnectorServiceRequest; use Google\Protobuf\FieldMask; use Google\Rpc\Status; @@ -42,7 +43,7 @@ function update_client_connector_service_sample(string $clientConnectorServiceNa // Create a client. $clientConnectorServicesServiceClient = new ClientConnectorServicesServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $updateMask = new FieldMask(); $clientConnectorServiceIngress = new Ingress(); $clientConnectorServiceEgress = new Egress(); @@ -50,14 +51,14 @@ function update_client_connector_service_sample(string $clientConnectorServiceNa ->setName($clientConnectorServiceName) ->setIngress($clientConnectorServiceIngress) ->setEgress($clientConnectorServiceEgress); + $request = (new UpdateClientConnectorServiceRequest()) + ->setUpdateMask($updateMask) + ->setClientConnectorService($clientConnectorService); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $clientConnectorServicesServiceClient->updateClientConnectorService( - $updateMask, - $clientConnectorService - ); + $response = $clientConnectorServicesServiceClient->updateClientConnectorService($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/BeyondCorpClientConnectorServices/src/V1/Client/BaseClient/ClientConnectorServicesServiceBaseClient.php b/BeyondCorpClientConnectorServices/src/V1/Client/BaseClient/ClientConnectorServicesServiceBaseClient.php new file mode 100644 index 000000000000..e13994660faa --- /dev/null +++ b/BeyondCorpClientConnectorServices/src/V1/Client/BaseClient/ClientConnectorServicesServiceBaseClient.php @@ -0,0 +1,548 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/client_connector_services_service_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/client_connector_services_service_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/client_connector_services_service_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/client_connector_services_service_rest_client_config.php', + ], + ], + ]; + } + + /** + * Return an OperationsClient object with the same endpoint as $this. + * + * @return OperationsClient + */ + public function getOperationsClient() + { + return $this->operationsClient; + } + + /** + * Resume an existing long running operation that was previously started by a long + * running API method. If $methodName is not provided, or does not match a long + * running API method, then the operation can still be resumed, but the + * OperationResponse object will not deserialize the final response. + * + * @param string $operationName The name of the long running operation + * @param string $methodName The name of the method used to start the operation + * + * @return OperationResponse + */ + public function resumeOperation($operationName, $methodName = null) + { + $options = isset($this->descriptors[$methodName]['longRunning']) ? $this->descriptors[$methodName]['longRunning'] : []; + $operation = new OperationResponse($operationName, $this->getOperationsClient(), $options); + $operation->reload(); + return $operation; + } + + /** + * Formats a string containing the fully-qualified path to represent a + * client_connector_service resource. + * + * @param string $project + * @param string $location + * @param string $clientConnectorService + * + * @return string The formatted client_connector_service resource. + */ + public static function clientConnectorServiceName(string $project, string $location, string $clientConnectorService): string + { + return self::getPathTemplate('clientConnectorService')->render([ + 'project' => $project, + 'location' => $location, + 'client_connector_service' => $clientConnectorService, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a location + * resource. + * + * @param string $project + * @param string $location + * + * @return string The formatted location resource. + */ + public static function locationName(string $project, string $location): string + { + return self::getPathTemplate('location')->render([ + 'project' => $project, + 'location' => $location, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * Template: Pattern + * - clientConnectorService: projects/{project}/locations/{location}/clientConnectorServices/{client_connector_service} + * - location: projects/{project}/locations/{location} + * + * The optional $template argument can be supplied to specify a particular pattern, + * and must match one of the templates listed above. If no $template argument is + * provided, or if the $template argument does not match one of the templates + * listed, then parseName will check each of the supported templates, and return + * the first match. + * + * @param string $formattedName The formatted name string + * @param string $template Optional name of template to match + * + * @return array An associative array from name component IDs to component values. + * + * @throws ValidationException If $formattedName could not be matched. + */ + public static function parseName(string $formattedName, string $template = null): array + { + return self::parseFormattedName($formattedName, $template); + } + + /** + * Constructor. + * + * @param array $options { + * Optional. Options for configuring the service API wrapper. + * + * @type string $apiEndpoint + * The address of the API remote host. May optionally include the port, formatted + * as ":". Default 'beyondcorp.googleapis.com:443'. + * @type string|array|FetchAuthTokenInterface|CredentialsWrapper $credentials + * The credentials to be used by the client to authorize API calls. This option + * accepts either a path to a credentials file, or a decoded credentials file as a + * PHP array. + * *Advanced usage*: In addition, this option can also accept a pre-constructed + * {@see \Google\Auth\FetchAuthTokenInterface} object or + * {@see \Google\ApiCore\CredentialsWrapper} object. Note that when one of these + * objects are provided, any settings in $credentialsConfig will be ignored. + * @type array $credentialsConfig + * Options used to configure credentials, including auth token caching, for the + * client. For a full list of supporting configuration options, see + * {@see \Google\ApiCore\CredentialsWrapper::build()} . + * @type bool $disableRetries + * Determines whether or not retries defined by the client configuration should be + * disabled. Defaults to `false`. + * @type string|array $clientConfig + * Client method configuration, including retry settings. This option can be either + * a path to a JSON file, or a PHP array containing the decoded JSON data. By + * default this settings points to the default client config file, which is + * provided in the resources folder. + * @type string|TransportInterface $transport + * The transport used for executing network requests. May be either the string + * `rest` or `grpc`. Defaults to `grpc` if gRPC support is detected on the system. + * *Advanced usage*: Additionally, it is possible to pass in an already + * instantiated {@see \Google\ApiCore\Transport\TransportInterface} object. Note + * that when this object is provided, any settings in $transportConfig, and any + * $apiEndpoint setting, will be ignored. + * @type array $transportConfig + * Configuration options that will be used to construct the transport. Options for + * each supported transport type should be passed in a key for that transport. For + * example: + * $transportConfig = [ + * 'grpc' => [...], + * 'rest' => [...], + * ]; + * See the {@see \Google\ApiCore\Transport\GrpcTransport::build()} and + * {@see \Google\ApiCore\Transport\RestTransport::build()} methods for the + * supported options. + * @type callable $clientCertSource + * A callable which returns the client cert as a string. This can be used to + * provide a certificate and private key to the transport layer for mTLS. + * } + * + * @throws ValidationException + */ + public function __construct(array $options = []) + { + $clientOptions = $this->buildClientOptions($options); + $this->setClientOptions($clientOptions); + $this->operationsClient = $this->createOperationsClient($clientOptions); + } + + /** Handles execution of the async variants for each documented method. */ + public function __call($method, $args) + { + if (substr($method, -5) !== 'Async') { + trigger_error('Call to undefined method ' . __CLASS__ . "::$method()", E_USER_ERROR); + } + + array_unshift($args, substr($method, 0, -5)); + return call_user_func_array([$this, 'startAsyncCall'], $args); + } + + /** + * Creates a new ClientConnectorService in a given project and location. + * + * The async variant is {@see self::createClientConnectorServiceAsync()} . + * + * @param CreateClientConnectorServiceRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function createClientConnectorService(CreateClientConnectorServiceRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('CreateClientConnectorService', $request, $callOptions)->wait(); + } + + /** + * Deletes a single ClientConnectorService. + * + * The async variant is {@see self::deleteClientConnectorServiceAsync()} . + * + * @param DeleteClientConnectorServiceRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function deleteClientConnectorService(DeleteClientConnectorServiceRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('DeleteClientConnectorService', $request, $callOptions)->wait(); + } + + /** + * Gets details of a single ClientConnectorService. + * + * The async variant is {@see self::getClientConnectorServiceAsync()} . + * + * @param GetClientConnectorServiceRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return ClientConnectorService + * + * @throws ApiException Thrown if the API call fails. + */ + public function getClientConnectorService(GetClientConnectorServiceRequest $request, array $callOptions = []): ClientConnectorService + { + return $this->startApiCall('GetClientConnectorService', $request, $callOptions)->wait(); + } + + /** + * Lists ClientConnectorServices in a given project and location. + * + * The async variant is {@see self::listClientConnectorServicesAsync()} . + * + * @param ListClientConnectorServicesRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listClientConnectorServices(ListClientConnectorServicesRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListClientConnectorServices', $request, $callOptions); + } + + /** + * Updates the parameters of a single ClientConnectorService. + * + * The async variant is {@see self::updateClientConnectorServiceAsync()} . + * + * @param UpdateClientConnectorServiceRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function updateClientConnectorService(UpdateClientConnectorServiceRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('UpdateClientConnectorService', $request, $callOptions)->wait(); + } + + /** + * Gets information about a location. + * + * The async variant is {@see self::getLocationAsync()} . + * + * @param GetLocationRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Location + * + * @throws ApiException Thrown if the API call fails. + */ + public function getLocation(GetLocationRequest $request, array $callOptions = []): Location + { + return $this->startApiCall('GetLocation', $request, $callOptions)->wait(); + } + + /** + * Lists information about the supported locations for this service. + * + * The async variant is {@see self::listLocationsAsync()} . + * + * @param ListLocationsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listLocations(ListLocationsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListLocations', $request, $callOptions); + } + + /** + * Gets the access control policy for a resource. Returns an empty policy + if the resource exists and does not have a policy set. + * + * The async variant is {@see self::getIamPolicyAsync()} . + * + * @param GetIamPolicyRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Policy + * + * @throws ApiException Thrown if the API call fails. + */ + public function getIamPolicy(GetIamPolicyRequest $request, array $callOptions = []): Policy + { + return $this->startApiCall('GetIamPolicy', $request, $callOptions)->wait(); + } + + /** + * Sets the access control policy on the specified resource. Replaces + any existing policy. + + Can return `NOT_FOUND`, `INVALID_ARGUMENT`, and `PERMISSION_DENIED` + errors. + * + * The async variant is {@see self::setIamPolicyAsync()} . + * + * @param SetIamPolicyRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Policy + * + * @throws ApiException Thrown if the API call fails. + */ + public function setIamPolicy(SetIamPolicyRequest $request, array $callOptions = []): Policy + { + return $this->startApiCall('SetIamPolicy', $request, $callOptions)->wait(); + } + + /** + * Returns permissions that a caller has on the specified resource. If the + resource does not exist, this will return an empty set of + permissions, not a `NOT_FOUND` error. + + Note: This operation is designed to be used for building + permission-aware UIs and command-line tools, not for authorization + checking. This operation may "fail open" without warning. + * + * The async variant is {@see self::testIamPermissionsAsync()} . + * + * @param TestIamPermissionsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return TestIamPermissionsResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function testIamPermissions(TestIamPermissionsRequest $request, array $callOptions = []): TestIamPermissionsResponse + { + return $this->startApiCall('TestIamPermissions', $request, $callOptions)->wait(); + } +} diff --git a/BeyondCorpClientConnectorServices/src/V1/Client/ClientConnectorServicesServiceClient.php b/BeyondCorpClientConnectorServices/src/V1/Client/ClientConnectorServicesServiceClient.php new file mode 100644 index 000000000000..4bcc0e46ce3d --- /dev/null +++ b/BeyondCorpClientConnectorServices/src/V1/Client/ClientConnectorServicesServiceClient.php @@ -0,0 +1,40 @@ +setParent($parent) + ->setClientConnectorService($clientConnectorService) + ->setClientConnectorServiceId($clientConnectorServiceId); + } + /** * Constructor. * diff --git a/BeyondCorpClientConnectorServices/src/V1/DeleteClientConnectorServiceRequest.php b/BeyondCorpClientConnectorServices/src/V1/DeleteClientConnectorServiceRequest.php index 017759dcad65..fc6657258aaa 100644 --- a/BeyondCorpClientConnectorServices/src/V1/DeleteClientConnectorServiceRequest.php +++ b/BeyondCorpClientConnectorServices/src/V1/DeleteClientConnectorServiceRequest.php @@ -45,6 +45,20 @@ class DeleteClientConnectorServiceRequest extends \Google\Protobuf\Internal\Mess */ private $validate_only = false; + /** + * @param string $name Required. Name of the resource. Please see + * {@see ClientConnectorServicesServiceClient::clientConnectorServiceName()} for help formatting this field. + * + * @return \Google\Cloud\BeyondCorp\ClientConnectorServices\V1\DeleteClientConnectorServiceRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/BeyondCorpClientConnectorServices/src/V1/GetClientConnectorServiceRequest.php b/BeyondCorpClientConnectorServices/src/V1/GetClientConnectorServiceRequest.php index 9f5e66ef8ef1..26a116ab1704 100644 --- a/BeyondCorpClientConnectorServices/src/V1/GetClientConnectorServiceRequest.php +++ b/BeyondCorpClientConnectorServices/src/V1/GetClientConnectorServiceRequest.php @@ -22,6 +22,20 @@ class GetClientConnectorServiceRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. Name of the resource. Please see + * {@see ClientConnectorServicesServiceClient::clientConnectorServiceName()} for help formatting this field. + * + * @return \Google\Cloud\BeyondCorp\ClientConnectorServices\V1\GetClientConnectorServiceRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/BeyondCorpClientConnectorServices/src/V1/ListClientConnectorServicesRequest.php b/BeyondCorpClientConnectorServices/src/V1/ListClientConnectorServicesRequest.php index 0cc0e0f3e005..5710d7889096 100644 --- a/BeyondCorpClientConnectorServices/src/V1/ListClientConnectorServicesRequest.php +++ b/BeyondCorpClientConnectorServices/src/V1/ListClientConnectorServicesRequest.php @@ -47,6 +47,20 @@ class ListClientConnectorServicesRequest extends \Google\Protobuf\Internal\Messa */ private $order_by = ''; + /** + * @param string $parent Required. Parent value for ListClientConnectorServicesRequest. Please see + * {@see ClientConnectorServicesServiceClient::locationName()} for help formatting this field. + * + * @return \Google\Cloud\BeyondCorp\ClientConnectorServices\V1\ListClientConnectorServicesRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/BeyondCorpClientConnectorServices/src/V1/UpdateClientConnectorServiceRequest.php b/BeyondCorpClientConnectorServices/src/V1/UpdateClientConnectorServiceRequest.php index 39853b3178a4..faf952ce4900 100644 --- a/BeyondCorpClientConnectorServices/src/V1/UpdateClientConnectorServiceRequest.php +++ b/BeyondCorpClientConnectorServices/src/V1/UpdateClientConnectorServiceRequest.php @@ -62,6 +62,27 @@ class UpdateClientConnectorServiceRequest extends \Google\Protobuf\Internal\Mess */ private $allow_missing = false; + /** + * @param \Google\Cloud\BeyondCorp\ClientConnectorServices\V1\ClientConnectorService $clientConnectorService Required. The resource being updated. + * @param \Google\Protobuf\FieldMask $updateMask Required. Field mask is used to specify the fields to be overwritten in the + * ClientConnectorService resource by the update. + * The fields specified in the update_mask are relative to the resource, not + * the full request. A field will be overwritten if it is in the mask. If the + * user does not provide a mask then all fields will be overwritten. + * + * Mutable fields: display_name. + * + * @return \Google\Cloud\BeyondCorp\ClientConnectorServices\V1\UpdateClientConnectorServiceRequest + * + * @experimental + */ + public static function build(\Google\Cloud\BeyondCorp\ClientConnectorServices\V1\ClientConnectorService $clientConnectorService, \Google\Protobuf\FieldMask $updateMask): self + { + return (new self()) + ->setClientConnectorService($clientConnectorService) + ->setUpdateMask($updateMask); + } + /** * Constructor. * diff --git a/BeyondCorpClientConnectorServices/src/V1/resources/client_connector_services_service_descriptor_config.php b/BeyondCorpClientConnectorServices/src/V1/resources/client_connector_services_service_descriptor_config.php index b30050512aa7..593d5772ad92 100644 --- a/BeyondCorpClientConnectorServices/src/V1/resources/client_connector_services_service_descriptor_config.php +++ b/BeyondCorpClientConnectorServices/src/V1/resources/client_connector_services_service_descriptor_config.php @@ -12,6 +12,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'DeleteClientConnectorService' => [ 'longRunning' => [ @@ -22,6 +31,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'UpdateClientConnectorService' => [ 'longRunning' => [ @@ -32,6 +50,28 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'client_connector_service.name', + 'fieldAccessors' => [ + 'getClientConnectorService', + 'getName', + ], + ], + ], + ], + 'GetClientConnectorService' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\BeyondCorp\ClientConnectorServices\V1\ClientConnectorService', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'ListClientConnectorServices' => [ 'pageStreaming' => [ @@ -42,8 +82,28 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getClientConnectorServices', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\BeyondCorp\ClientConnectorServices\V1\ListClientConnectorServicesResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'GetLocation' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Location\Location', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], 'interfaceOverride' => 'google.cloud.location.Locations', ], 'ListLocations' => [ @@ -55,17 +115,61 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getLocations', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\Location\ListLocationsResponse', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], 'interfaceOverride' => 'google.cloud.location.Locations', ], 'GetIamPolicy' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\Policy', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], 'interfaceOverride' => 'google.iam.v1.IAMPolicy', ], 'SetIamPolicy' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\Policy', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], 'interfaceOverride' => 'google.iam.v1.IAMPolicy', ], 'TestIamPermissions' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\TestIamPermissionsResponse', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], 'interfaceOverride' => 'google.iam.v1.IAMPolicy', ], + 'templateMap' => [ + 'clientConnectorService' => 'projects/{project}/locations/{location}/clientConnectorServices/{client_connector_service}', + 'location' => 'projects/{project}/locations/{location}', + ], ], ], ]; diff --git a/BeyondCorpClientConnectorServices/tests/Unit/V1/Client/ClientConnectorServicesServiceClientTest.php b/BeyondCorpClientConnectorServices/tests/Unit/V1/Client/ClientConnectorServicesServiceClientTest.php new file mode 100644 index 000000000000..c7880d02594f --- /dev/null +++ b/BeyondCorpClientConnectorServices/tests/Unit/V1/Client/ClientConnectorServicesServiceClientTest.php @@ -0,0 +1,1037 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return ClientConnectorServicesServiceClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new ClientConnectorServicesServiceClient($options); + } + + /** @test */ + public function createClientConnectorServiceTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/createClientConnectorServiceTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $displayName = 'displayName1615086568'; + $expectedResponse = new ClientConnectorService(); + $expectedResponse->setName($name); + $expectedResponse->setDisplayName($displayName); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createClientConnectorServiceTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $clientConnectorService = new ClientConnectorService(); + $clientConnectorServiceName = 'clientConnectorServiceName1804966078'; + $clientConnectorService->setName($clientConnectorServiceName); + $clientConnectorServiceIngress = new Ingress(); + $clientConnectorService->setIngress($clientConnectorServiceIngress); + $clientConnectorServiceEgress = new Egress(); + $clientConnectorService->setEgress($clientConnectorServiceEgress); + $request = (new CreateClientConnectorServiceRequest()) + ->setParent($formattedParent) + ->setClientConnectorService($clientConnectorService); + $response = $gapicClient->createClientConnectorService($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.beyondcorp.clientconnectorservices.v1.ClientConnectorServicesService/CreateClientConnectorService', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getClientConnectorService(); + $this->assertProtobufEquals($clientConnectorService, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createClientConnectorServiceTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function createClientConnectorServiceExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/createClientConnectorServiceTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $clientConnectorService = new ClientConnectorService(); + $clientConnectorServiceName = 'clientConnectorServiceName1804966078'; + $clientConnectorService->setName($clientConnectorServiceName); + $clientConnectorServiceIngress = new Ingress(); + $clientConnectorService->setIngress($clientConnectorServiceIngress); + $clientConnectorServiceEgress = new Egress(); + $clientConnectorService->setEgress($clientConnectorServiceEgress); + $request = (new CreateClientConnectorServiceRequest()) + ->setParent($formattedParent) + ->setClientConnectorService($clientConnectorService); + $response = $gapicClient->createClientConnectorService($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createClientConnectorServiceTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function deleteClientConnectorServiceTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/deleteClientConnectorServiceTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new GPBEmpty(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/deleteClientConnectorServiceTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->clientConnectorServiceName('[PROJECT]', '[LOCATION]', '[CLIENT_CONNECTOR_SERVICE]'); + $request = (new DeleteClientConnectorServiceRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteClientConnectorService($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.beyondcorp.clientconnectorservices.v1.ClientConnectorServicesService/DeleteClientConnectorService', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteClientConnectorServiceTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function deleteClientConnectorServiceExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/deleteClientConnectorServiceTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->clientConnectorServiceName('[PROJECT]', '[LOCATION]', '[CLIENT_CONNECTOR_SERVICE]'); + $request = (new DeleteClientConnectorServiceRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteClientConnectorService($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteClientConnectorServiceTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function getClientConnectorServiceTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $displayName = 'displayName1615086568'; + $expectedResponse = new ClientConnectorService(); + $expectedResponse->setName($name2); + $expectedResponse->setDisplayName($displayName); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->clientConnectorServiceName('[PROJECT]', '[LOCATION]', '[CLIENT_CONNECTOR_SERVICE]'); + $request = (new GetClientConnectorServiceRequest()) + ->setName($formattedName); + $response = $gapicClient->getClientConnectorService($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.beyondcorp.clientconnectorservices.v1.ClientConnectorServicesService/GetClientConnectorService', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getClientConnectorServiceExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->clientConnectorServiceName('[PROJECT]', '[LOCATION]', '[CLIENT_CONNECTOR_SERVICE]'); + $request = (new GetClientConnectorServiceRequest()) + ->setName($formattedName); + try { + $gapicClient->getClientConnectorService($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listClientConnectorServicesTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $clientConnectorServicesElement = new ClientConnectorService(); + $clientConnectorServices = [ + $clientConnectorServicesElement, + ]; + $expectedResponse = new ListClientConnectorServicesResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setClientConnectorServices($clientConnectorServices); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListClientConnectorServicesRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listClientConnectorServices($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getClientConnectorServices()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.beyondcorp.clientconnectorservices.v1.ClientConnectorServicesService/ListClientConnectorServices', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listClientConnectorServicesExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListClientConnectorServicesRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listClientConnectorServices($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function updateClientConnectorServiceTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/updateClientConnectorServiceTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $displayName = 'displayName1615086568'; + $expectedResponse = new ClientConnectorService(); + $expectedResponse->setName($name); + $expectedResponse->setDisplayName($displayName); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/updateClientConnectorServiceTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $updateMask = new FieldMask(); + $clientConnectorService = new ClientConnectorService(); + $clientConnectorServiceName = 'clientConnectorServiceName1804966078'; + $clientConnectorService->setName($clientConnectorServiceName); + $clientConnectorServiceIngress = new Ingress(); + $clientConnectorService->setIngress($clientConnectorServiceIngress); + $clientConnectorServiceEgress = new Egress(); + $clientConnectorService->setEgress($clientConnectorServiceEgress); + $request = (new UpdateClientConnectorServiceRequest()) + ->setUpdateMask($updateMask) + ->setClientConnectorService($clientConnectorService); + $response = $gapicClient->updateClientConnectorService($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.beyondcorp.clientconnectorservices.v1.ClientConnectorServicesService/UpdateClientConnectorService', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getUpdateMask(); + $this->assertProtobufEquals($updateMask, $actualValue); + $actualValue = $actualApiRequestObject->getClientConnectorService(); + $this->assertProtobufEquals($clientConnectorService, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateClientConnectorServiceTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function updateClientConnectorServiceExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/updateClientConnectorServiceTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $updateMask = new FieldMask(); + $clientConnectorService = new ClientConnectorService(); + $clientConnectorServiceName = 'clientConnectorServiceName1804966078'; + $clientConnectorService->setName($clientConnectorServiceName); + $clientConnectorServiceIngress = new Ingress(); + $clientConnectorService->setIngress($clientConnectorServiceIngress); + $clientConnectorServiceEgress = new Egress(); + $clientConnectorService->setEgress($clientConnectorServiceEgress); + $request = (new UpdateClientConnectorServiceRequest()) + ->setUpdateMask($updateMask) + ->setClientConnectorService($clientConnectorService); + $response = $gapicClient->updateClientConnectorService($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateClientConnectorServiceTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function getLocationTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $locationId = 'locationId552319461'; + $displayName = 'displayName1615086568'; + $expectedResponse = new Location(); + $expectedResponse->setName($name2); + $expectedResponse->setLocationId($locationId); + $expectedResponse->setDisplayName($displayName); + $transport->addResponse($expectedResponse); + $request = new GetLocationRequest(); + $response = $gapicClient->getLocation($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.location.Locations/GetLocation', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getLocationExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + $request = new GetLocationRequest(); + try { + $gapicClient->getLocation($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listLocationsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $locationsElement = new Location(); + $locations = [ + $locationsElement, + ]; + $expectedResponse = new ListLocationsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setLocations($locations); + $transport->addResponse($expectedResponse); + $request = new ListLocationsRequest(); + $response = $gapicClient->listLocations($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getLocations()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.location.Locations/ListLocations', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listLocationsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + $request = new ListLocationsRequest(); + try { + $gapicClient->listLocations($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getIamPolicyTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $version = 351608024; + $etag = '21'; + $expectedResponse = new Policy(); + $expectedResponse->setVersion($version); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + $response = $gapicClient->getIamPolicy($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.iam.v1.IAMPolicy/GetIamPolicy', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getIamPolicyExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $resource = 'resource-341064690'; + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + try { + $gapicClient->getIamPolicy($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function setIamPolicyTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $version = 351608024; + $etag = '21'; + $expectedResponse = new Policy(); + $expectedResponse->setVersion($version); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $policy = new Policy(); + $request = (new SetIamPolicyRequest()) + ->setResource($resource) + ->setPolicy($policy); + $response = $gapicClient->setIamPolicy($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.iam.v1.IAMPolicy/SetIamPolicy', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $actualValue = $actualRequestObject->getPolicy(); + $this->assertProtobufEquals($policy, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function setIamPolicyExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $resource = 'resource-341064690'; + $policy = new Policy(); + $request = (new SetIamPolicyRequest()) + ->setResource($resource) + ->setPolicy($policy); + try { + $gapicClient->setIamPolicy($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function testIamPermissionsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new TestIamPermissionsResponse(); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $permissions = []; + $request = (new TestIamPermissionsRequest()) + ->setResource($resource) + ->setPermissions($permissions); + $response = $gapicClient->testIamPermissions($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.iam.v1.IAMPolicy/TestIamPermissions', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $actualValue = $actualRequestObject->getPermissions(); + $this->assertProtobufEquals($permissions, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function testIamPermissionsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $resource = 'resource-341064690'; + $permissions = []; + $request = (new TestIamPermissionsRequest()) + ->setResource($resource) + ->setPermissions($permissions); + try { + $gapicClient->testIamPermissions($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createClientConnectorServiceAsyncTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/createClientConnectorServiceTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $displayName = 'displayName1615086568'; + $expectedResponse = new ClientConnectorService(); + $expectedResponse->setName($name); + $expectedResponse->setDisplayName($displayName); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createClientConnectorServiceTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $clientConnectorService = new ClientConnectorService(); + $clientConnectorServiceName = 'clientConnectorServiceName1804966078'; + $clientConnectorService->setName($clientConnectorServiceName); + $clientConnectorServiceIngress = new Ingress(); + $clientConnectorService->setIngress($clientConnectorServiceIngress); + $clientConnectorServiceEgress = new Egress(); + $clientConnectorService->setEgress($clientConnectorServiceEgress); + $request = (new CreateClientConnectorServiceRequest()) + ->setParent($formattedParent) + ->setClientConnectorService($clientConnectorService); + $response = $gapicClient->createClientConnectorServiceAsync($request)->wait(); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.beyondcorp.clientconnectorservices.v1.ClientConnectorServicesService/CreateClientConnectorService', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getClientConnectorService(); + $this->assertProtobufEquals($clientConnectorService, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createClientConnectorServiceTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } +} diff --git a/BeyondCorpClientGateways/samples/V1/ClientGatewaysServiceClient/create_client_gateway.php b/BeyondCorpClientGateways/samples/V1/ClientGatewaysServiceClient/create_client_gateway.php index 576ea4992421..cb7685453f53 100644 --- a/BeyondCorpClientGateways/samples/V1/ClientGatewaysServiceClient/create_client_gateway.php +++ b/BeyondCorpClientGateways/samples/V1/ClientGatewaysServiceClient/create_client_gateway.php @@ -26,7 +26,8 @@ use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; use Google\Cloud\BeyondCorp\ClientGateways\V1\ClientGateway; -use Google\Cloud\BeyondCorp\ClientGateways\V1\ClientGatewaysServiceClient; +use Google\Cloud\BeyondCorp\ClientGateways\V1\Client\ClientGatewaysServiceClient; +use Google\Cloud\BeyondCorp\ClientGateways\V1\CreateClientGatewayRequest; use Google\Rpc\Status; /** @@ -41,14 +42,17 @@ function create_client_gateway_sample(string $formattedParent, string $clientGat // Create a client. $clientGatewaysServiceClient = new ClientGatewaysServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $clientGateway = (new ClientGateway()) ->setName($clientGatewayName); + $request = (new CreateClientGatewayRequest()) + ->setParent($formattedParent) + ->setClientGateway($clientGateway); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $clientGatewaysServiceClient->createClientGateway($formattedParent, $clientGateway); + $response = $clientGatewaysServiceClient->createClientGateway($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/BeyondCorpClientGateways/samples/V1/ClientGatewaysServiceClient/delete_client_gateway.php b/BeyondCorpClientGateways/samples/V1/ClientGatewaysServiceClient/delete_client_gateway.php index fcd5ceae7543..15e560c4d6b9 100644 --- a/BeyondCorpClientGateways/samples/V1/ClientGatewaysServiceClient/delete_client_gateway.php +++ b/BeyondCorpClientGateways/samples/V1/ClientGatewaysServiceClient/delete_client_gateway.php @@ -25,7 +25,8 @@ // [START beyondcorp_v1_generated_ClientGatewaysService_DeleteClientGateway_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\BeyondCorp\ClientGateways\V1\ClientGatewaysServiceClient; +use Google\Cloud\BeyondCorp\ClientGateways\V1\Client\ClientGatewaysServiceClient; +use Google\Cloud\BeyondCorp\ClientGateways\V1\DeleteClientGatewayRequest; use Google\Rpc\Status; /** @@ -39,10 +40,14 @@ function delete_client_gateway_sample(string $formattedName): void // Create a client. $clientGatewaysServiceClient = new ClientGatewaysServiceClient(); + // Prepare the request message. + $request = (new DeleteClientGatewayRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $clientGatewaysServiceClient->deleteClientGateway($formattedName); + $response = $clientGatewaysServiceClient->deleteClientGateway($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/BeyondCorpClientGateways/samples/V1/ClientGatewaysServiceClient/get_client_gateway.php b/BeyondCorpClientGateways/samples/V1/ClientGatewaysServiceClient/get_client_gateway.php index 62fb897e7ab5..7cb8f2f2c9dd 100644 --- a/BeyondCorpClientGateways/samples/V1/ClientGatewaysServiceClient/get_client_gateway.php +++ b/BeyondCorpClientGateways/samples/V1/ClientGatewaysServiceClient/get_client_gateway.php @@ -25,7 +25,8 @@ // [START beyondcorp_v1_generated_ClientGatewaysService_GetClientGateway_sync] use Google\ApiCore\ApiException; use Google\Cloud\BeyondCorp\ClientGateways\V1\ClientGateway; -use Google\Cloud\BeyondCorp\ClientGateways\V1\ClientGatewaysServiceClient; +use Google\Cloud\BeyondCorp\ClientGateways\V1\Client\ClientGatewaysServiceClient; +use Google\Cloud\BeyondCorp\ClientGateways\V1\GetClientGatewayRequest; /** * Gets details of a single ClientGateway. @@ -38,10 +39,14 @@ function get_client_gateway_sample(string $formattedName): void // Create a client. $clientGatewaysServiceClient = new ClientGatewaysServiceClient(); + // Prepare the request message. + $request = (new GetClientGatewayRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var ClientGateway $response */ - $response = $clientGatewaysServiceClient->getClientGateway($formattedName); + $response = $clientGatewaysServiceClient->getClientGateway($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BeyondCorpClientGateways/samples/V1/ClientGatewaysServiceClient/get_iam_policy.php b/BeyondCorpClientGateways/samples/V1/ClientGatewaysServiceClient/get_iam_policy.php index 3bde499c3b21..0626d899b1cf 100644 --- a/BeyondCorpClientGateways/samples/V1/ClientGatewaysServiceClient/get_iam_policy.php +++ b/BeyondCorpClientGateways/samples/V1/ClientGatewaysServiceClient/get_iam_policy.php @@ -24,7 +24,8 @@ // [START beyondcorp_v1_generated_ClientGatewaysService_GetIamPolicy_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BeyondCorp\ClientGateways\V1\ClientGatewaysServiceClient; +use Google\Cloud\BeyondCorp\ClientGateways\V1\Client\ClientGatewaysServiceClient; +use Google\Cloud\Iam\V1\GetIamPolicyRequest; use Google\Cloud\Iam\V1\Policy; /** @@ -39,10 +40,14 @@ function get_iam_policy_sample(string $resource): void // Create a client. $clientGatewaysServiceClient = new ClientGatewaysServiceClient(); + // Prepare the request message. + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + // Call the API and handle any network failures. try { /** @var Policy $response */ - $response = $clientGatewaysServiceClient->getIamPolicy($resource); + $response = $clientGatewaysServiceClient->getIamPolicy($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BeyondCorpClientGateways/samples/V1/ClientGatewaysServiceClient/get_location.php b/BeyondCorpClientGateways/samples/V1/ClientGatewaysServiceClient/get_location.php index 0bd772c7fd31..616db7d03c31 100644 --- a/BeyondCorpClientGateways/samples/V1/ClientGatewaysServiceClient/get_location.php +++ b/BeyondCorpClientGateways/samples/V1/ClientGatewaysServiceClient/get_location.php @@ -24,7 +24,8 @@ // [START beyondcorp_v1_generated_ClientGatewaysService_GetLocation_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BeyondCorp\ClientGateways\V1\ClientGatewaysServiceClient; +use Google\Cloud\BeyondCorp\ClientGateways\V1\Client\ClientGatewaysServiceClient; +use Google\Cloud\Location\GetLocationRequest; use Google\Cloud\Location\Location; /** @@ -41,10 +42,13 @@ function get_location_sample(): void // Create a client. $clientGatewaysServiceClient = new ClientGatewaysServiceClient(); + // Prepare the request message. + $request = new GetLocationRequest(); + // Call the API and handle any network failures. try { /** @var Location $response */ - $response = $clientGatewaysServiceClient->getLocation(); + $response = $clientGatewaysServiceClient->getLocation($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BeyondCorpClientGateways/samples/V1/ClientGatewaysServiceClient/list_client_gateways.php b/BeyondCorpClientGateways/samples/V1/ClientGatewaysServiceClient/list_client_gateways.php index fa48f143948f..ec65dca4daba 100644 --- a/BeyondCorpClientGateways/samples/V1/ClientGatewaysServiceClient/list_client_gateways.php +++ b/BeyondCorpClientGateways/samples/V1/ClientGatewaysServiceClient/list_client_gateways.php @@ -26,7 +26,8 @@ use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; use Google\Cloud\BeyondCorp\ClientGateways\V1\ClientGateway; -use Google\Cloud\BeyondCorp\ClientGateways\V1\ClientGatewaysServiceClient; +use Google\Cloud\BeyondCorp\ClientGateways\V1\Client\ClientGatewaysServiceClient; +use Google\Cloud\BeyondCorp\ClientGateways\V1\ListClientGatewaysRequest; /** * Lists ClientGateways in a given project and location. @@ -39,10 +40,14 @@ function list_client_gateways_sample(string $formattedParent): void // Create a client. $clientGatewaysServiceClient = new ClientGatewaysServiceClient(); + // Prepare the request message. + $request = (new ListClientGatewaysRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $clientGatewaysServiceClient->listClientGateways($formattedParent); + $response = $clientGatewaysServiceClient->listClientGateways($request); /** @var ClientGateway $element */ foreach ($response as $element) { diff --git a/BeyondCorpClientGateways/samples/V1/ClientGatewaysServiceClient/list_locations.php b/BeyondCorpClientGateways/samples/V1/ClientGatewaysServiceClient/list_locations.php index 443ad77ea4d2..2d325c7d13e1 100644 --- a/BeyondCorpClientGateways/samples/V1/ClientGatewaysServiceClient/list_locations.php +++ b/BeyondCorpClientGateways/samples/V1/ClientGatewaysServiceClient/list_locations.php @@ -25,7 +25,8 @@ // [START beyondcorp_v1_generated_ClientGatewaysService_ListLocations_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; -use Google\Cloud\BeyondCorp\ClientGateways\V1\ClientGatewaysServiceClient; +use Google\Cloud\BeyondCorp\ClientGateways\V1\Client\ClientGatewaysServiceClient; +use Google\Cloud\Location\ListLocationsRequest; use Google\Cloud\Location\Location; /** @@ -42,10 +43,13 @@ function list_locations_sample(): void // Create a client. $clientGatewaysServiceClient = new ClientGatewaysServiceClient(); + // Prepare the request message. + $request = new ListLocationsRequest(); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $clientGatewaysServiceClient->listLocations(); + $response = $clientGatewaysServiceClient->listLocations($request); /** @var Location $element */ foreach ($response as $element) { diff --git a/BeyondCorpClientGateways/samples/V1/ClientGatewaysServiceClient/set_iam_policy.php b/BeyondCorpClientGateways/samples/V1/ClientGatewaysServiceClient/set_iam_policy.php index c03023366361..70d3d84322a8 100644 --- a/BeyondCorpClientGateways/samples/V1/ClientGatewaysServiceClient/set_iam_policy.php +++ b/BeyondCorpClientGateways/samples/V1/ClientGatewaysServiceClient/set_iam_policy.php @@ -24,8 +24,9 @@ // [START beyondcorp_v1_generated_ClientGatewaysService_SetIamPolicy_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BeyondCorp\ClientGateways\V1\ClientGatewaysServiceClient; +use Google\Cloud\BeyondCorp\ClientGateways\V1\Client\ClientGatewaysServiceClient; use Google\Cloud\Iam\V1\Policy; +use Google\Cloud\Iam\V1\SetIamPolicyRequest; /** * Sets the access control policy on the specified resource. Replaces @@ -42,13 +43,16 @@ function set_iam_policy_sample(string $resource): void // Create a client. $clientGatewaysServiceClient = new ClientGatewaysServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $policy = new Policy(); + $request = (new SetIamPolicyRequest()) + ->setResource($resource) + ->setPolicy($policy); // Call the API and handle any network failures. try { /** @var Policy $response */ - $response = $clientGatewaysServiceClient->setIamPolicy($resource, $policy); + $response = $clientGatewaysServiceClient->setIamPolicy($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BeyondCorpClientGateways/samples/V1/ClientGatewaysServiceClient/test_iam_permissions.php b/BeyondCorpClientGateways/samples/V1/ClientGatewaysServiceClient/test_iam_permissions.php index 193ca7d827f8..a05775eebcb8 100644 --- a/BeyondCorpClientGateways/samples/V1/ClientGatewaysServiceClient/test_iam_permissions.php +++ b/BeyondCorpClientGateways/samples/V1/ClientGatewaysServiceClient/test_iam_permissions.php @@ -24,7 +24,8 @@ // [START beyondcorp_v1_generated_ClientGatewaysService_TestIamPermissions_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BeyondCorp\ClientGateways\V1\ClientGatewaysServiceClient; +use Google\Cloud\BeyondCorp\ClientGateways\V1\Client\ClientGatewaysServiceClient; +use Google\Cloud\Iam\V1\TestIamPermissionsRequest; use Google\Cloud\Iam\V1\TestIamPermissionsResponse; /** @@ -48,13 +49,16 @@ function test_iam_permissions_sample(string $resource, string $permissionsElemen // Create a client. $clientGatewaysServiceClient = new ClientGatewaysServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $permissions = [$permissionsElement,]; + $request = (new TestIamPermissionsRequest()) + ->setResource($resource) + ->setPermissions($permissions); // Call the API and handle any network failures. try { /** @var TestIamPermissionsResponse $response */ - $response = $clientGatewaysServiceClient->testIamPermissions($resource, $permissions); + $response = $clientGatewaysServiceClient->testIamPermissions($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BeyondCorpClientGateways/src/V1/Client/BaseClient/ClientGatewaysServiceBaseClient.php b/BeyondCorpClientGateways/src/V1/Client/BaseClient/ClientGatewaysServiceBaseClient.php new file mode 100644 index 000000000000..74784b2a75e5 --- /dev/null +++ b/BeyondCorpClientGateways/src/V1/Client/BaseClient/ClientGatewaysServiceBaseClient.php @@ -0,0 +1,522 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/client_gateways_service_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/client_gateways_service_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/client_gateways_service_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/client_gateways_service_rest_client_config.php', + ], + ], + ]; + } + + /** + * Return an OperationsClient object with the same endpoint as $this. + * + * @return OperationsClient + */ + public function getOperationsClient() + { + return $this->operationsClient; + } + + /** + * Resume an existing long running operation that was previously started by a long + * running API method. If $methodName is not provided, or does not match a long + * running API method, then the operation can still be resumed, but the + * OperationResponse object will not deserialize the final response. + * + * @param string $operationName The name of the long running operation + * @param string $methodName The name of the method used to start the operation + * + * @return OperationResponse + */ + public function resumeOperation($operationName, $methodName = null) + { + $options = isset($this->descriptors[$methodName]['longRunning']) ? $this->descriptors[$methodName]['longRunning'] : []; + $operation = new OperationResponse($operationName, $this->getOperationsClient(), $options); + $operation->reload(); + return $operation; + } + + /** + * Formats a string containing the fully-qualified path to represent a + * client_gateway resource. + * + * @param string $project + * @param string $location + * @param string $clientGateway + * + * @return string The formatted client_gateway resource. + */ + public static function clientGatewayName(string $project, string $location, string $clientGateway): string + { + return self::getPathTemplate('clientGateway')->render([ + 'project' => $project, + 'location' => $location, + 'client_gateway' => $clientGateway, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a location + * resource. + * + * @param string $project + * @param string $location + * + * @return string The formatted location resource. + */ + public static function locationName(string $project, string $location): string + { + return self::getPathTemplate('location')->render([ + 'project' => $project, + 'location' => $location, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * Template: Pattern + * - clientGateway: projects/{project}/locations/{location}/clientGateways/{client_gateway} + * - location: projects/{project}/locations/{location} + * + * The optional $template argument can be supplied to specify a particular pattern, + * and must match one of the templates listed above. If no $template argument is + * provided, or if the $template argument does not match one of the templates + * listed, then parseName will check each of the supported templates, and return + * the first match. + * + * @param string $formattedName The formatted name string + * @param string $template Optional name of template to match + * + * @return array An associative array from name component IDs to component values. + * + * @throws ValidationException If $formattedName could not be matched. + */ + public static function parseName(string $formattedName, string $template = null): array + { + return self::parseFormattedName($formattedName, $template); + } + + /** + * Constructor. + * + * @param array $options { + * Optional. Options for configuring the service API wrapper. + * + * @type string $apiEndpoint + * The address of the API remote host. May optionally include the port, formatted + * as ":". Default 'beyondcorp.googleapis.com:443'. + * @type string|array|FetchAuthTokenInterface|CredentialsWrapper $credentials + * The credentials to be used by the client to authorize API calls. This option + * accepts either a path to a credentials file, or a decoded credentials file as a + * PHP array. + * *Advanced usage*: In addition, this option can also accept a pre-constructed + * {@see \Google\Auth\FetchAuthTokenInterface} object or + * {@see \Google\ApiCore\CredentialsWrapper} object. Note that when one of these + * objects are provided, any settings in $credentialsConfig will be ignored. + * @type array $credentialsConfig + * Options used to configure credentials, including auth token caching, for the + * client. For a full list of supporting configuration options, see + * {@see \Google\ApiCore\CredentialsWrapper::build()} . + * @type bool $disableRetries + * Determines whether or not retries defined by the client configuration should be + * disabled. Defaults to `false`. + * @type string|array $clientConfig + * Client method configuration, including retry settings. This option can be either + * a path to a JSON file, or a PHP array containing the decoded JSON data. By + * default this settings points to the default client config file, which is + * provided in the resources folder. + * @type string|TransportInterface $transport + * The transport used for executing network requests. May be either the string + * `rest` or `grpc`. Defaults to `grpc` if gRPC support is detected on the system. + * *Advanced usage*: Additionally, it is possible to pass in an already + * instantiated {@see \Google\ApiCore\Transport\TransportInterface} object. Note + * that when this object is provided, any settings in $transportConfig, and any + * $apiEndpoint setting, will be ignored. + * @type array $transportConfig + * Configuration options that will be used to construct the transport. Options for + * each supported transport type should be passed in a key for that transport. For + * example: + * $transportConfig = [ + * 'grpc' => [...], + * 'rest' => [...], + * ]; + * See the {@see \Google\ApiCore\Transport\GrpcTransport::build()} and + * {@see \Google\ApiCore\Transport\RestTransport::build()} methods for the + * supported options. + * @type callable $clientCertSource + * A callable which returns the client cert as a string. This can be used to + * provide a certificate and private key to the transport layer for mTLS. + * } + * + * @throws ValidationException + */ + public function __construct(array $options = []) + { + $clientOptions = $this->buildClientOptions($options); + $this->setClientOptions($clientOptions); + $this->operationsClient = $this->createOperationsClient($clientOptions); + } + + /** Handles execution of the async variants for each documented method. */ + public function __call($method, $args) + { + if (substr($method, -5) !== 'Async') { + trigger_error('Call to undefined method ' . __CLASS__ . "::$method()", E_USER_ERROR); + } + + array_unshift($args, substr($method, 0, -5)); + return call_user_func_array([$this, 'startAsyncCall'], $args); + } + + /** + * Creates a new ClientGateway in a given project and location. + * + * The async variant is {@see self::createClientGatewayAsync()} . + * + * @param CreateClientGatewayRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function createClientGateway(CreateClientGatewayRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('CreateClientGateway', $request, $callOptions)->wait(); + } + + /** + * Deletes a single ClientGateway. + * + * The async variant is {@see self::deleteClientGatewayAsync()} . + * + * @param DeleteClientGatewayRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function deleteClientGateway(DeleteClientGatewayRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('DeleteClientGateway', $request, $callOptions)->wait(); + } + + /** + * Gets details of a single ClientGateway. + * + * The async variant is {@see self::getClientGatewayAsync()} . + * + * @param GetClientGatewayRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return ClientGateway + * + * @throws ApiException Thrown if the API call fails. + */ + public function getClientGateway(GetClientGatewayRequest $request, array $callOptions = []): ClientGateway + { + return $this->startApiCall('GetClientGateway', $request, $callOptions)->wait(); + } + + /** + * Lists ClientGateways in a given project and location. + * + * The async variant is {@see self::listClientGatewaysAsync()} . + * + * @param ListClientGatewaysRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listClientGateways(ListClientGatewaysRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListClientGateways', $request, $callOptions); + } + + /** + * Gets information about a location. + * + * The async variant is {@see self::getLocationAsync()} . + * + * @param GetLocationRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Location + * + * @throws ApiException Thrown if the API call fails. + */ + public function getLocation(GetLocationRequest $request, array $callOptions = []): Location + { + return $this->startApiCall('GetLocation', $request, $callOptions)->wait(); + } + + /** + * Lists information about the supported locations for this service. + * + * The async variant is {@see self::listLocationsAsync()} . + * + * @param ListLocationsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listLocations(ListLocationsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListLocations', $request, $callOptions); + } + + /** + * Gets the access control policy for a resource. Returns an empty policy + if the resource exists and does not have a policy set. + * + * The async variant is {@see self::getIamPolicyAsync()} . + * + * @param GetIamPolicyRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Policy + * + * @throws ApiException Thrown if the API call fails. + */ + public function getIamPolicy(GetIamPolicyRequest $request, array $callOptions = []): Policy + { + return $this->startApiCall('GetIamPolicy', $request, $callOptions)->wait(); + } + + /** + * Sets the access control policy on the specified resource. Replaces + any existing policy. + + Can return `NOT_FOUND`, `INVALID_ARGUMENT`, and `PERMISSION_DENIED` + errors. + * + * The async variant is {@see self::setIamPolicyAsync()} . + * + * @param SetIamPolicyRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Policy + * + * @throws ApiException Thrown if the API call fails. + */ + public function setIamPolicy(SetIamPolicyRequest $request, array $callOptions = []): Policy + { + return $this->startApiCall('SetIamPolicy', $request, $callOptions)->wait(); + } + + /** + * Returns permissions that a caller has on the specified resource. If the + resource does not exist, this will return an empty set of + permissions, not a `NOT_FOUND` error. + + Note: This operation is designed to be used for building + permission-aware UIs and command-line tools, not for authorization + checking. This operation may "fail open" without warning. + * + * The async variant is {@see self::testIamPermissionsAsync()} . + * + * @param TestIamPermissionsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return TestIamPermissionsResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function testIamPermissions(TestIamPermissionsRequest $request, array $callOptions = []): TestIamPermissionsResponse + { + return $this->startApiCall('TestIamPermissions', $request, $callOptions)->wait(); + } +} diff --git a/BeyondCorpClientGateways/src/V1/Client/ClientGatewaysServiceClient.php b/BeyondCorpClientGateways/src/V1/Client/ClientGatewaysServiceClient.php new file mode 100644 index 000000000000..68d0596349ac --- /dev/null +++ b/BeyondCorpClientGateways/src/V1/Client/ClientGatewaysServiceClient.php @@ -0,0 +1,40 @@ +setParent($parent) + ->setClientGateway($clientGateway) + ->setClientGatewayId($clientGatewayId); + } + /** * Constructor. * diff --git a/BeyondCorpClientGateways/src/V1/DeleteClientGatewayRequest.php b/BeyondCorpClientGateways/src/V1/DeleteClientGatewayRequest.php index d27645ecd8f8..c04514891435 100644 --- a/BeyondCorpClientGateways/src/V1/DeleteClientGatewayRequest.php +++ b/BeyondCorpClientGateways/src/V1/DeleteClientGatewayRequest.php @@ -45,6 +45,20 @@ class DeleteClientGatewayRequest extends \Google\Protobuf\Internal\Message */ private $validate_only = false; + /** + * @param string $name Required. Name of the resource + * Please see {@see ClientGatewaysServiceClient::clientGatewayName()} for help formatting this field. + * + * @return \Google\Cloud\BeyondCorp\ClientGateways\V1\DeleteClientGatewayRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/BeyondCorpClientGateways/src/V1/GetClientGatewayRequest.php b/BeyondCorpClientGateways/src/V1/GetClientGatewayRequest.php index 60b21245bda8..3c30cfa9ba60 100644 --- a/BeyondCorpClientGateways/src/V1/GetClientGatewayRequest.php +++ b/BeyondCorpClientGateways/src/V1/GetClientGatewayRequest.php @@ -22,6 +22,20 @@ class GetClientGatewayRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. Name of the resource + * Please see {@see ClientGatewaysServiceClient::clientGatewayName()} for help formatting this field. + * + * @return \Google\Cloud\BeyondCorp\ClientGateways\V1\GetClientGatewayRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/BeyondCorpClientGateways/src/V1/ListClientGatewaysRequest.php b/BeyondCorpClientGateways/src/V1/ListClientGatewaysRequest.php index 54a79d59b667..4ebfc6b5de23 100644 --- a/BeyondCorpClientGateways/src/V1/ListClientGatewaysRequest.php +++ b/BeyondCorpClientGateways/src/V1/ListClientGatewaysRequest.php @@ -47,6 +47,20 @@ class ListClientGatewaysRequest extends \Google\Protobuf\Internal\Message */ private $order_by = ''; + /** + * @param string $parent Required. Parent value for ListClientGatewaysRequest. Please see + * {@see ClientGatewaysServiceClient::locationName()} for help formatting this field. + * + * @return \Google\Cloud\BeyondCorp\ClientGateways\V1\ListClientGatewaysRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/BeyondCorpClientGateways/src/V1/resources/client_gateways_service_descriptor_config.php b/BeyondCorpClientGateways/src/V1/resources/client_gateways_service_descriptor_config.php index 4e071f167f70..053175b674ef 100644 --- a/BeyondCorpClientGateways/src/V1/resources/client_gateways_service_descriptor_config.php +++ b/BeyondCorpClientGateways/src/V1/resources/client_gateways_service_descriptor_config.php @@ -12,6 +12,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'DeleteClientGateway' => [ 'longRunning' => [ @@ -22,6 +31,27 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetClientGateway' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\BeyondCorp\ClientGateways\V1\ClientGateway', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'ListClientGateways' => [ 'pageStreaming' => [ @@ -32,8 +62,28 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getClientGateways', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\BeyondCorp\ClientGateways\V1\ListClientGatewaysResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'GetLocation' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Location\Location', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], 'interfaceOverride' => 'google.cloud.location.Locations', ], 'ListLocations' => [ @@ -45,17 +95,61 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getLocations', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\Location\ListLocationsResponse', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], 'interfaceOverride' => 'google.cloud.location.Locations', ], 'GetIamPolicy' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\Policy', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], 'interfaceOverride' => 'google.iam.v1.IAMPolicy', ], 'SetIamPolicy' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\Policy', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], 'interfaceOverride' => 'google.iam.v1.IAMPolicy', ], 'TestIamPermissions' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\TestIamPermissionsResponse', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], 'interfaceOverride' => 'google.iam.v1.IAMPolicy', ], + 'templateMap' => [ + 'clientGateway' => 'projects/{project}/locations/{location}/clientGateways/{client_gateway}', + 'location' => 'projects/{project}/locations/{location}', + ], ], ], ]; diff --git a/BeyondCorpClientGateways/tests/Unit/V1/Client/ClientGatewaysServiceClientTest.php b/BeyondCorpClientGateways/tests/Unit/V1/Client/ClientGatewaysServiceClientTest.php new file mode 100644 index 000000000000..f4477b2e932c --- /dev/null +++ b/BeyondCorpClientGateways/tests/Unit/V1/Client/ClientGatewaysServiceClientTest.php @@ -0,0 +1,884 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return ClientGatewaysServiceClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new ClientGatewaysServiceClient($options); + } + + /** @test */ + public function createClientGatewayTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/createClientGatewayTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $id = 'id3355'; + $clientConnectorService = 'clientConnectorService-1152817841'; + $expectedResponse = new ClientGateway(); + $expectedResponse->setName($name); + $expectedResponse->setId($id); + $expectedResponse->setClientConnectorService($clientConnectorService); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createClientGatewayTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $clientGateway = new ClientGateway(); + $clientGatewayName = 'clientGatewayName-1795593692'; + $clientGateway->setName($clientGatewayName); + $request = (new CreateClientGatewayRequest()) + ->setParent($formattedParent) + ->setClientGateway($clientGateway); + $response = $gapicClient->createClientGateway($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.beyondcorp.clientgateways.v1.ClientGatewaysService/CreateClientGateway', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getClientGateway(); + $this->assertProtobufEquals($clientGateway, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createClientGatewayTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function createClientGatewayExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/createClientGatewayTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $clientGateway = new ClientGateway(); + $clientGatewayName = 'clientGatewayName-1795593692'; + $clientGateway->setName($clientGatewayName); + $request = (new CreateClientGatewayRequest()) + ->setParent($formattedParent) + ->setClientGateway($clientGateway); + $response = $gapicClient->createClientGateway($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createClientGatewayTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function deleteClientGatewayTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/deleteClientGatewayTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new GPBEmpty(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/deleteClientGatewayTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->clientGatewayName('[PROJECT]', '[LOCATION]', '[CLIENT_GATEWAY]'); + $request = (new DeleteClientGatewayRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteClientGateway($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.beyondcorp.clientgateways.v1.ClientGatewaysService/DeleteClientGateway', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteClientGatewayTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function deleteClientGatewayExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/deleteClientGatewayTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->clientGatewayName('[PROJECT]', '[LOCATION]', '[CLIENT_GATEWAY]'); + $request = (new DeleteClientGatewayRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteClientGateway($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteClientGatewayTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function getClientGatewayTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $id = 'id3355'; + $clientConnectorService = 'clientConnectorService-1152817841'; + $expectedResponse = new ClientGateway(); + $expectedResponse->setName($name2); + $expectedResponse->setId($id); + $expectedResponse->setClientConnectorService($clientConnectorService); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->clientGatewayName('[PROJECT]', '[LOCATION]', '[CLIENT_GATEWAY]'); + $request = (new GetClientGatewayRequest()) + ->setName($formattedName); + $response = $gapicClient->getClientGateway($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.beyondcorp.clientgateways.v1.ClientGatewaysService/GetClientGateway', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getClientGatewayExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->clientGatewayName('[PROJECT]', '[LOCATION]', '[CLIENT_GATEWAY]'); + $request = (new GetClientGatewayRequest()) + ->setName($formattedName); + try { + $gapicClient->getClientGateway($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listClientGatewaysTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $clientGatewaysElement = new ClientGateway(); + $clientGateways = [ + $clientGatewaysElement, + ]; + $expectedResponse = new ListClientGatewaysResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setClientGateways($clientGateways); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListClientGatewaysRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listClientGateways($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getClientGateways()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.beyondcorp.clientgateways.v1.ClientGatewaysService/ListClientGateways', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listClientGatewaysExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListClientGatewaysRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listClientGateways($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getLocationTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $locationId = 'locationId552319461'; + $displayName = 'displayName1615086568'; + $expectedResponse = new Location(); + $expectedResponse->setName($name2); + $expectedResponse->setLocationId($locationId); + $expectedResponse->setDisplayName($displayName); + $transport->addResponse($expectedResponse); + $request = new GetLocationRequest(); + $response = $gapicClient->getLocation($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.location.Locations/GetLocation', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getLocationExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + $request = new GetLocationRequest(); + try { + $gapicClient->getLocation($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listLocationsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $locationsElement = new Location(); + $locations = [ + $locationsElement, + ]; + $expectedResponse = new ListLocationsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setLocations($locations); + $transport->addResponse($expectedResponse); + $request = new ListLocationsRequest(); + $response = $gapicClient->listLocations($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getLocations()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.location.Locations/ListLocations', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listLocationsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + $request = new ListLocationsRequest(); + try { + $gapicClient->listLocations($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getIamPolicyTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $version = 351608024; + $etag = '21'; + $expectedResponse = new Policy(); + $expectedResponse->setVersion($version); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + $response = $gapicClient->getIamPolicy($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.iam.v1.IAMPolicy/GetIamPolicy', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getIamPolicyExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $resource = 'resource-341064690'; + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + try { + $gapicClient->getIamPolicy($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function setIamPolicyTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $version = 351608024; + $etag = '21'; + $expectedResponse = new Policy(); + $expectedResponse->setVersion($version); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $policy = new Policy(); + $request = (new SetIamPolicyRequest()) + ->setResource($resource) + ->setPolicy($policy); + $response = $gapicClient->setIamPolicy($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.iam.v1.IAMPolicy/SetIamPolicy', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $actualValue = $actualRequestObject->getPolicy(); + $this->assertProtobufEquals($policy, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function setIamPolicyExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $resource = 'resource-341064690'; + $policy = new Policy(); + $request = (new SetIamPolicyRequest()) + ->setResource($resource) + ->setPolicy($policy); + try { + $gapicClient->setIamPolicy($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function testIamPermissionsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new TestIamPermissionsResponse(); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $permissions = []; + $request = (new TestIamPermissionsRequest()) + ->setResource($resource) + ->setPermissions($permissions); + $response = $gapicClient->testIamPermissions($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.iam.v1.IAMPolicy/TestIamPermissions', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $actualValue = $actualRequestObject->getPermissions(); + $this->assertProtobufEquals($permissions, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function testIamPermissionsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $resource = 'resource-341064690'; + $permissions = []; + $request = (new TestIamPermissionsRequest()) + ->setResource($resource) + ->setPermissions($permissions); + try { + $gapicClient->testIamPermissions($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createClientGatewayAsyncTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/createClientGatewayTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $id = 'id3355'; + $clientConnectorService = 'clientConnectorService-1152817841'; + $expectedResponse = new ClientGateway(); + $expectedResponse->setName($name); + $expectedResponse->setId($id); + $expectedResponse->setClientConnectorService($clientConnectorService); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createClientGatewayTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $clientGateway = new ClientGateway(); + $clientGatewayName = 'clientGatewayName-1795593692'; + $clientGateway->setName($clientGatewayName); + $request = (new CreateClientGatewayRequest()) + ->setParent($formattedParent) + ->setClientGateway($clientGateway); + $response = $gapicClient->createClientGatewayAsync($request)->wait(); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.beyondcorp.clientgateways.v1.ClientGatewaysService/CreateClientGateway', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getClientGateway(); + $this->assertProtobufEquals($clientGateway, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createClientGatewayTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } +} diff --git a/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/create_data_exchange.php b/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/create_data_exchange.php index a83ac1984b1a..42b07979f897 100644 --- a/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/create_data_exchange.php +++ b/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/create_data_exchange.php @@ -24,7 +24,8 @@ // [START analyticshub_v1_generated_AnalyticsHubService_CreateDataExchange_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BigQuery\AnalyticsHub\V1\AnalyticsHubServiceClient; +use Google\Cloud\BigQuery\AnalyticsHub\V1\Client\AnalyticsHubServiceClient; +use Google\Cloud\BigQuery\AnalyticsHub\V1\CreateDataExchangeRequest; use Google\Cloud\BigQuery\AnalyticsHub\V1\DataExchange; /** @@ -52,18 +53,18 @@ function create_data_exchange_sample( // Create a client. $analyticsHubServiceClient = new AnalyticsHubServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $dataExchange = (new DataExchange()) ->setDisplayName($dataExchangeDisplayName); + $request = (new CreateDataExchangeRequest()) + ->setParent($formattedParent) + ->setDataExchangeId($dataExchangeId) + ->setDataExchange($dataExchange); // Call the API and handle any network failures. try { /** @var DataExchange $response */ - $response = $analyticsHubServiceClient->createDataExchange( - $formattedParent, - $dataExchangeId, - $dataExchange - ); + $response = $analyticsHubServiceClient->createDataExchange($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/create_listing.php b/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/create_listing.php index daa592f40bd3..ff83f1462ce5 100644 --- a/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/create_listing.php +++ b/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/create_listing.php @@ -24,7 +24,8 @@ // [START analyticshub_v1_generated_AnalyticsHubService_CreateListing_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BigQuery\AnalyticsHub\V1\AnalyticsHubServiceClient; +use Google\Cloud\BigQuery\AnalyticsHub\V1\Client\AnalyticsHubServiceClient; +use Google\Cloud\BigQuery\AnalyticsHub\V1\CreateListingRequest; use Google\Cloud\BigQuery\AnalyticsHub\V1\Listing; use Google\Cloud\BigQuery\AnalyticsHub\V1\Listing\BigQueryDatasetSource; @@ -53,16 +54,20 @@ function create_listing_sample( // Create a client. $analyticsHubServiceClient = new AnalyticsHubServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $listingBigqueryDataset = new BigQueryDatasetSource(); $listing = (new Listing()) ->setBigqueryDataset($listingBigqueryDataset) ->setDisplayName($listingDisplayName); + $request = (new CreateListingRequest()) + ->setParent($formattedParent) + ->setListingId($listingId) + ->setListing($listing); // Call the API and handle any network failures. try { /** @var Listing $response */ - $response = $analyticsHubServiceClient->createListing($formattedParent, $listingId, $listing); + $response = $analyticsHubServiceClient->createListing($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/delete_data_exchange.php b/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/delete_data_exchange.php index 4b50c01c5077..468aeef96c68 100644 --- a/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/delete_data_exchange.php +++ b/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/delete_data_exchange.php @@ -24,7 +24,8 @@ // [START analyticshub_v1_generated_AnalyticsHubService_DeleteDataExchange_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BigQuery\AnalyticsHub\V1\AnalyticsHubServiceClient; +use Google\Cloud\BigQuery\AnalyticsHub\V1\Client\AnalyticsHubServiceClient; +use Google\Cloud\BigQuery\AnalyticsHub\V1\DeleteDataExchangeRequest; /** * Deletes an existing data exchange. @@ -38,9 +39,13 @@ function delete_data_exchange_sample(string $formattedName): void // Create a client. $analyticsHubServiceClient = new AnalyticsHubServiceClient(); + // Prepare the request message. + $request = (new DeleteDataExchangeRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { - $analyticsHubServiceClient->deleteDataExchange($formattedName); + $analyticsHubServiceClient->deleteDataExchange($request); printf('Call completed successfully.' . PHP_EOL); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/delete_listing.php b/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/delete_listing.php index 7c23a646cfa9..6d8555d76c19 100644 --- a/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/delete_listing.php +++ b/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/delete_listing.php @@ -24,7 +24,8 @@ // [START analyticshub_v1_generated_AnalyticsHubService_DeleteListing_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BigQuery\AnalyticsHub\V1\AnalyticsHubServiceClient; +use Google\Cloud\BigQuery\AnalyticsHub\V1\Client\AnalyticsHubServiceClient; +use Google\Cloud\BigQuery\AnalyticsHub\V1\DeleteListingRequest; /** * Deletes a listing. @@ -38,9 +39,13 @@ function delete_listing_sample(string $formattedName): void // Create a client. $analyticsHubServiceClient = new AnalyticsHubServiceClient(); + // Prepare the request message. + $request = (new DeleteListingRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { - $analyticsHubServiceClient->deleteListing($formattedName); + $analyticsHubServiceClient->deleteListing($request); printf('Call completed successfully.' . PHP_EOL); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/get_data_exchange.php b/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/get_data_exchange.php index 8613e888cf4e..8f10086ee2ef 100644 --- a/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/get_data_exchange.php +++ b/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/get_data_exchange.php @@ -24,8 +24,9 @@ // [START analyticshub_v1_generated_AnalyticsHubService_GetDataExchange_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BigQuery\AnalyticsHub\V1\AnalyticsHubServiceClient; +use Google\Cloud\BigQuery\AnalyticsHub\V1\Client\AnalyticsHubServiceClient; use Google\Cloud\BigQuery\AnalyticsHub\V1\DataExchange; +use Google\Cloud\BigQuery\AnalyticsHub\V1\GetDataExchangeRequest; /** * Gets the details of a data exchange. @@ -39,10 +40,14 @@ function get_data_exchange_sample(string $formattedName): void // Create a client. $analyticsHubServiceClient = new AnalyticsHubServiceClient(); + // Prepare the request message. + $request = (new GetDataExchangeRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var DataExchange $response */ - $response = $analyticsHubServiceClient->getDataExchange($formattedName); + $response = $analyticsHubServiceClient->getDataExchange($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/get_iam_policy.php b/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/get_iam_policy.php index f4b8278a5308..80c290c01d3a 100644 --- a/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/get_iam_policy.php +++ b/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/get_iam_policy.php @@ -24,7 +24,8 @@ // [START analyticshub_v1_generated_AnalyticsHubService_GetIamPolicy_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BigQuery\AnalyticsHub\V1\AnalyticsHubServiceClient; +use Google\Cloud\BigQuery\AnalyticsHub\V1\Client\AnalyticsHubServiceClient; +use Google\Cloud\Iam\V1\GetIamPolicyRequest; use Google\Cloud\Iam\V1\Policy; /** @@ -38,10 +39,14 @@ function get_iam_policy_sample(string $resource): void // Create a client. $analyticsHubServiceClient = new AnalyticsHubServiceClient(); + // Prepare the request message. + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + // Call the API and handle any network failures. try { /** @var Policy $response */ - $response = $analyticsHubServiceClient->getIamPolicy($resource); + $response = $analyticsHubServiceClient->getIamPolicy($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/get_listing.php b/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/get_listing.php index 59977710acba..b971b326e415 100644 --- a/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/get_listing.php +++ b/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/get_listing.php @@ -24,7 +24,8 @@ // [START analyticshub_v1_generated_AnalyticsHubService_GetListing_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BigQuery\AnalyticsHub\V1\AnalyticsHubServiceClient; +use Google\Cloud\BigQuery\AnalyticsHub\V1\Client\AnalyticsHubServiceClient; +use Google\Cloud\BigQuery\AnalyticsHub\V1\GetListingRequest; use Google\Cloud\BigQuery\AnalyticsHub\V1\Listing; /** @@ -39,10 +40,14 @@ function get_listing_sample(string $formattedName): void // Create a client. $analyticsHubServiceClient = new AnalyticsHubServiceClient(); + // Prepare the request message. + $request = (new GetListingRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var Listing $response */ - $response = $analyticsHubServiceClient->getListing($formattedName); + $response = $analyticsHubServiceClient->getListing($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/list_data_exchanges.php b/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/list_data_exchanges.php index c35ab9001da8..9b24b958f637 100644 --- a/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/list_data_exchanges.php +++ b/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/list_data_exchanges.php @@ -25,8 +25,9 @@ // [START analyticshub_v1_generated_AnalyticsHubService_ListDataExchanges_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; -use Google\Cloud\BigQuery\AnalyticsHub\V1\AnalyticsHubServiceClient; +use Google\Cloud\BigQuery\AnalyticsHub\V1\Client\AnalyticsHubServiceClient; use Google\Cloud\BigQuery\AnalyticsHub\V1\DataExchange; +use Google\Cloud\BigQuery\AnalyticsHub\V1\ListDataExchangesRequest; /** * Lists all data exchanges in a given project and location. @@ -40,10 +41,14 @@ function list_data_exchanges_sample(string $formattedParent): void // Create a client. $analyticsHubServiceClient = new AnalyticsHubServiceClient(); + // Prepare the request message. + $request = (new ListDataExchangesRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $analyticsHubServiceClient->listDataExchanges($formattedParent); + $response = $analyticsHubServiceClient->listDataExchanges($request); /** @var DataExchange $element */ foreach ($response as $element) { diff --git a/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/list_listings.php b/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/list_listings.php index 44e64a247054..52dcf7c162b4 100644 --- a/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/list_listings.php +++ b/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/list_listings.php @@ -25,7 +25,8 @@ // [START analyticshub_v1_generated_AnalyticsHubService_ListListings_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; -use Google\Cloud\BigQuery\AnalyticsHub\V1\AnalyticsHubServiceClient; +use Google\Cloud\BigQuery\AnalyticsHub\V1\Client\AnalyticsHubServiceClient; +use Google\Cloud\BigQuery\AnalyticsHub\V1\ListListingsRequest; use Google\Cloud\BigQuery\AnalyticsHub\V1\Listing; /** @@ -40,10 +41,14 @@ function list_listings_sample(string $formattedParent): void // Create a client. $analyticsHubServiceClient = new AnalyticsHubServiceClient(); + // Prepare the request message. + $request = (new ListListingsRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $analyticsHubServiceClient->listListings($formattedParent); + $response = $analyticsHubServiceClient->listListings($request); /** @var Listing $element */ foreach ($response as $element) { diff --git a/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/list_org_data_exchanges.php b/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/list_org_data_exchanges.php index 03a255ae5e27..1d83c83d207e 100644 --- a/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/list_org_data_exchanges.php +++ b/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/list_org_data_exchanges.php @@ -25,8 +25,9 @@ // [START analyticshub_v1_generated_AnalyticsHubService_ListOrgDataExchanges_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; -use Google\Cloud\BigQuery\AnalyticsHub\V1\AnalyticsHubServiceClient; +use Google\Cloud\BigQuery\AnalyticsHub\V1\Client\AnalyticsHubServiceClient; use Google\Cloud\BigQuery\AnalyticsHub\V1\DataExchange; +use Google\Cloud\BigQuery\AnalyticsHub\V1\ListOrgDataExchangesRequest; /** * Lists all data exchanges from projects in a given organization and @@ -40,10 +41,14 @@ function list_org_data_exchanges_sample(string $organization): void // Create a client. $analyticsHubServiceClient = new AnalyticsHubServiceClient(); + // Prepare the request message. + $request = (new ListOrgDataExchangesRequest()) + ->setOrganization($organization); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $analyticsHubServiceClient->listOrgDataExchanges($organization); + $response = $analyticsHubServiceClient->listOrgDataExchanges($request); /** @var DataExchange $element */ foreach ($response as $element) { diff --git a/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/set_iam_policy.php b/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/set_iam_policy.php index 2d62a068d065..06c03c656a50 100644 --- a/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/set_iam_policy.php +++ b/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/set_iam_policy.php @@ -24,8 +24,9 @@ // [START analyticshub_v1_generated_AnalyticsHubService_SetIamPolicy_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BigQuery\AnalyticsHub\V1\AnalyticsHubServiceClient; +use Google\Cloud\BigQuery\AnalyticsHub\V1\Client\AnalyticsHubServiceClient; use Google\Cloud\Iam\V1\Policy; +use Google\Cloud\Iam\V1\SetIamPolicyRequest; /** * Sets the IAM policy. @@ -38,13 +39,16 @@ function set_iam_policy_sample(string $resource): void // Create a client. $analyticsHubServiceClient = new AnalyticsHubServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $policy = new Policy(); + $request = (new SetIamPolicyRequest()) + ->setResource($resource) + ->setPolicy($policy); // Call the API and handle any network failures. try { /** @var Policy $response */ - $response = $analyticsHubServiceClient->setIamPolicy($resource, $policy); + $response = $analyticsHubServiceClient->setIamPolicy($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/subscribe_listing.php b/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/subscribe_listing.php index fea6a00194db..26e5c3fe2c53 100644 --- a/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/subscribe_listing.php +++ b/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/subscribe_listing.php @@ -24,7 +24,8 @@ // [START analyticshub_v1_generated_AnalyticsHubService_SubscribeListing_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BigQuery\AnalyticsHub\V1\AnalyticsHubServiceClient; +use Google\Cloud\BigQuery\AnalyticsHub\V1\Client\AnalyticsHubServiceClient; +use Google\Cloud\BigQuery\AnalyticsHub\V1\SubscribeListingRequest; use Google\Cloud\BigQuery\AnalyticsHub\V1\SubscribeListingResponse; /** @@ -44,10 +45,14 @@ function subscribe_listing_sample(string $formattedName): void // Create a client. $analyticsHubServiceClient = new AnalyticsHubServiceClient(); + // Prepare the request message. + $request = (new SubscribeListingRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var SubscribeListingResponse $response */ - $response = $analyticsHubServiceClient->subscribeListing($formattedName); + $response = $analyticsHubServiceClient->subscribeListing($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/test_iam_permissions.php b/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/test_iam_permissions.php index 6c052f5a8655..7df1d9215d93 100644 --- a/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/test_iam_permissions.php +++ b/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/test_iam_permissions.php @@ -24,7 +24,8 @@ // [START analyticshub_v1_generated_AnalyticsHubService_TestIamPermissions_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BigQuery\AnalyticsHub\V1\AnalyticsHubServiceClient; +use Google\Cloud\BigQuery\AnalyticsHub\V1\Client\AnalyticsHubServiceClient; +use Google\Cloud\Iam\V1\TestIamPermissionsRequest; use Google\Cloud\Iam\V1\TestIamPermissionsResponse; /** @@ -42,13 +43,16 @@ function test_iam_permissions_sample(string $resource, string $permissionsElemen // Create a client. $analyticsHubServiceClient = new AnalyticsHubServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $permissions = [$permissionsElement,]; + $request = (new TestIamPermissionsRequest()) + ->setResource($resource) + ->setPermissions($permissions); // Call the API and handle any network failures. try { /** @var TestIamPermissionsResponse $response */ - $response = $analyticsHubServiceClient->testIamPermissions($resource, $permissions); + $response = $analyticsHubServiceClient->testIamPermissions($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/update_data_exchange.php b/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/update_data_exchange.php index 8b1716a12e53..b35ba5907cbd 100644 --- a/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/update_data_exchange.php +++ b/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/update_data_exchange.php @@ -24,8 +24,9 @@ // [START analyticshub_v1_generated_AnalyticsHubService_UpdateDataExchange_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BigQuery\AnalyticsHub\V1\AnalyticsHubServiceClient; +use Google\Cloud\BigQuery\AnalyticsHub\V1\Client\AnalyticsHubServiceClient; use Google\Cloud\BigQuery\AnalyticsHub\V1\DataExchange; +use Google\Cloud\BigQuery\AnalyticsHub\V1\UpdateDataExchangeRequest; use Google\Protobuf\FieldMask; /** @@ -42,15 +43,18 @@ function update_data_exchange_sample(string $dataExchangeDisplayName): void // Create a client. $analyticsHubServiceClient = new AnalyticsHubServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $updateMask = new FieldMask(); $dataExchange = (new DataExchange()) ->setDisplayName($dataExchangeDisplayName); + $request = (new UpdateDataExchangeRequest()) + ->setUpdateMask($updateMask) + ->setDataExchange($dataExchange); // Call the API and handle any network failures. try { /** @var DataExchange $response */ - $response = $analyticsHubServiceClient->updateDataExchange($updateMask, $dataExchange); + $response = $analyticsHubServiceClient->updateDataExchange($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/update_listing.php b/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/update_listing.php index 2baa58eb8089..a37cfdc1f91a 100644 --- a/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/update_listing.php +++ b/BigQueryAnalyticsHub/samples/V1/AnalyticsHubServiceClient/update_listing.php @@ -24,9 +24,10 @@ // [START analyticshub_v1_generated_AnalyticsHubService_UpdateListing_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BigQuery\AnalyticsHub\V1\AnalyticsHubServiceClient; +use Google\Cloud\BigQuery\AnalyticsHub\V1\Client\AnalyticsHubServiceClient; use Google\Cloud\BigQuery\AnalyticsHub\V1\Listing; use Google\Cloud\BigQuery\AnalyticsHub\V1\Listing\BigQueryDatasetSource; +use Google\Cloud\BigQuery\AnalyticsHub\V1\UpdateListingRequest; use Google\Protobuf\FieldMask; /** @@ -43,17 +44,20 @@ function update_listing_sample(string $listingDisplayName): void // Create a client. $analyticsHubServiceClient = new AnalyticsHubServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $updateMask = new FieldMask(); $listingBigqueryDataset = new BigQueryDatasetSource(); $listing = (new Listing()) ->setBigqueryDataset($listingBigqueryDataset) ->setDisplayName($listingDisplayName); + $request = (new UpdateListingRequest()) + ->setUpdateMask($updateMask) + ->setListing($listing); // Call the API and handle any network failures. try { /** @var Listing $response */ - $response = $analyticsHubServiceClient->updateListing($updateMask, $listing); + $response = $analyticsHubServiceClient->updateListing($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BigQueryAnalyticsHub/src/V1/Client/AnalyticsHubServiceClient.php b/BigQueryAnalyticsHub/src/V1/Client/AnalyticsHubServiceClient.php new file mode 100644 index 000000000000..9177b15e52e3 --- /dev/null +++ b/BigQueryAnalyticsHub/src/V1/Client/AnalyticsHubServiceClient.php @@ -0,0 +1,40 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/analytics_hub_service_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/analytics_hub_service_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/analytics_hub_service_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/analytics_hub_service_rest_client_config.php', + ], + ], + ]; + } + + /** + * Formats a string containing the fully-qualified path to represent a + * data_exchange resource. + * + * @param string $project + * @param string $location + * @param string $dataExchange + * + * @return string The formatted data_exchange resource. + */ + public static function dataExchangeName(string $project, string $location, string $dataExchange): string + { + return self::getPathTemplate('dataExchange')->render([ + 'project' => $project, + 'location' => $location, + 'data_exchange' => $dataExchange, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a dataset + * resource. + * + * @param string $project + * @param string $dataset + * + * @return string The formatted dataset resource. + */ + public static function datasetName(string $project, string $dataset): string + { + return self::getPathTemplate('dataset')->render([ + 'project' => $project, + 'dataset' => $dataset, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a listing + * resource. + * + * @param string $project + * @param string $location + * @param string $dataExchange + * @param string $listing + * + * @return string The formatted listing resource. + */ + public static function listingName(string $project, string $location, string $dataExchange, string $listing): string + { + return self::getPathTemplate('listing')->render([ + 'project' => $project, + 'location' => $location, + 'data_exchange' => $dataExchange, + 'listing' => $listing, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a location + * resource. + * + * @param string $project + * @param string $location + * + * @return string The formatted location resource. + */ + public static function locationName(string $project, string $location): string + { + return self::getPathTemplate('location')->render([ + 'project' => $project, + 'location' => $location, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * Template: Pattern + * - dataExchange: projects/{project}/locations/{location}/dataExchanges/{data_exchange} + * - dataset: projects/{project}/datasets/{dataset} + * - listing: projects/{project}/locations/{location}/dataExchanges/{data_exchange}/listings/{listing} + * - location: projects/{project}/locations/{location} + * + * The optional $template argument can be supplied to specify a particular pattern, + * and must match one of the templates listed above. If no $template argument is + * provided, or if the $template argument does not match one of the templates + * listed, then parseName will check each of the supported templates, and return + * the first match. + * + * @param string $formattedName The formatted name string + * @param string $template Optional name of template to match + * + * @return array An associative array from name component IDs to component values. + * + * @throws ValidationException If $formattedName could not be matched. + */ + public static function parseName(string $formattedName, string $template = null): array + { + return self::parseFormattedName($formattedName, $template); + } + + /** + * Constructor. + * + * @param array $options { + * Optional. Options for configuring the service API wrapper. + * + * @type string $apiEndpoint + * The address of the API remote host. May optionally include the port, formatted + * as ":". Default 'analyticshub.googleapis.com:443'. + * @type string|array|FetchAuthTokenInterface|CredentialsWrapper $credentials + * The credentials to be used by the client to authorize API calls. This option + * accepts either a path to a credentials file, or a decoded credentials file as a + * PHP array. + * *Advanced usage*: In addition, this option can also accept a pre-constructed + * {@see \Google\Auth\FetchAuthTokenInterface} object or + * {@see \Google\ApiCore\CredentialsWrapper} object. Note that when one of these + * objects are provided, any settings in $credentialsConfig will be ignored. + * @type array $credentialsConfig + * Options used to configure credentials, including auth token caching, for the + * client. For a full list of supporting configuration options, see + * {@see \Google\ApiCore\CredentialsWrapper::build()} . + * @type bool $disableRetries + * Determines whether or not retries defined by the client configuration should be + * disabled. Defaults to `false`. + * @type string|array $clientConfig + * Client method configuration, including retry settings. This option can be either + * a path to a JSON file, or a PHP array containing the decoded JSON data. By + * default this settings points to the default client config file, which is + * provided in the resources folder. + * @type string|TransportInterface $transport + * The transport used for executing network requests. May be either the string + * `rest` or `grpc`. Defaults to `grpc` if gRPC support is detected on the system. + * *Advanced usage*: Additionally, it is possible to pass in an already + * instantiated {@see \Google\ApiCore\Transport\TransportInterface} object. Note + * that when this object is provided, any settings in $transportConfig, and any + * $apiEndpoint setting, will be ignored. + * @type array $transportConfig + * Configuration options that will be used to construct the transport. Options for + * each supported transport type should be passed in a key for that transport. For + * example: + * $transportConfig = [ + * 'grpc' => [...], + * 'rest' => [...], + * ]; + * See the {@see \Google\ApiCore\Transport\GrpcTransport::build()} and + * {@see \Google\ApiCore\Transport\RestTransport::build()} methods for the + * supported options. + * @type callable $clientCertSource + * A callable which returns the client cert as a string. This can be used to + * provide a certificate and private key to the transport layer for mTLS. + * } + * + * @throws ValidationException + */ + public function __construct(array $options = []) + { + $clientOptions = $this->buildClientOptions($options); + $this->setClientOptions($clientOptions); + } + + /** Handles execution of the async variants for each documented method. */ + public function __call($method, $args) + { + if (substr($method, -5) !== 'Async') { + trigger_error('Call to undefined method ' . __CLASS__ . "::$method()", E_USER_ERROR); + } + + array_unshift($args, substr($method, 0, -5)); + return call_user_func_array([$this, 'startAsyncCall'], $args); + } + + /** + * Creates a new data exchange. + * + * The async variant is {@see self::createDataExchangeAsync()} . + * + * @param CreateDataExchangeRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return DataExchange + * + * @throws ApiException Thrown if the API call fails. + */ + public function createDataExchange(CreateDataExchangeRequest $request, array $callOptions = []): DataExchange + { + return $this->startApiCall('CreateDataExchange', $request, $callOptions)->wait(); + } + + /** + * Creates a new listing. + * + * The async variant is {@see self::createListingAsync()} . + * + * @param CreateListingRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Listing + * + * @throws ApiException Thrown if the API call fails. + */ + public function createListing(CreateListingRequest $request, array $callOptions = []): Listing + { + return $this->startApiCall('CreateListing', $request, $callOptions)->wait(); + } + + /** + * Deletes an existing data exchange. + * + * The async variant is {@see self::deleteDataExchangeAsync()} . + * + * @param DeleteDataExchangeRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @throws ApiException Thrown if the API call fails. + */ + public function deleteDataExchange(DeleteDataExchangeRequest $request, array $callOptions = []): void + { + $this->startApiCall('DeleteDataExchange', $request, $callOptions)->wait(); + } + + /** + * Deletes a listing. + * + * The async variant is {@see self::deleteListingAsync()} . + * + * @param DeleteListingRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @throws ApiException Thrown if the API call fails. + */ + public function deleteListing(DeleteListingRequest $request, array $callOptions = []): void + { + $this->startApiCall('DeleteListing', $request, $callOptions)->wait(); + } + + /** + * Gets the details of a data exchange. + * + * The async variant is {@see self::getDataExchangeAsync()} . + * + * @param GetDataExchangeRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return DataExchange + * + * @throws ApiException Thrown if the API call fails. + */ + public function getDataExchange(GetDataExchangeRequest $request, array $callOptions = []): DataExchange + { + return $this->startApiCall('GetDataExchange', $request, $callOptions)->wait(); + } + + /** + * Gets the IAM policy. + * + * The async variant is {@see self::getIamPolicyAsync()} . + * + * @param GetIamPolicyRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Policy + * + * @throws ApiException Thrown if the API call fails. + */ + public function getIamPolicy(GetIamPolicyRequest $request, array $callOptions = []): Policy + { + return $this->startApiCall('GetIamPolicy', $request, $callOptions)->wait(); + } + + /** + * Gets the details of a listing. + * + * The async variant is {@see self::getListingAsync()} . + * + * @param GetListingRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Listing + * + * @throws ApiException Thrown if the API call fails. + */ + public function getListing(GetListingRequest $request, array $callOptions = []): Listing + { + return $this->startApiCall('GetListing', $request, $callOptions)->wait(); + } + + /** + * Lists all data exchanges in a given project and location. + * + * The async variant is {@see self::listDataExchangesAsync()} . + * + * @param ListDataExchangesRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listDataExchanges(ListDataExchangesRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListDataExchanges', $request, $callOptions); + } + + /** + * Lists all listings in a given project and location. + * + * The async variant is {@see self::listListingsAsync()} . + * + * @param ListListingsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listListings(ListListingsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListListings', $request, $callOptions); + } + + /** + * Lists all data exchanges from projects in a given organization and + * location. + * + * The async variant is {@see self::listOrgDataExchangesAsync()} . + * + * @param ListOrgDataExchangesRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listOrgDataExchanges(ListOrgDataExchangesRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListOrgDataExchanges', $request, $callOptions); + } + + /** + * Sets the IAM policy. + * + * The async variant is {@see self::setIamPolicyAsync()} . + * + * @param SetIamPolicyRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Policy + * + * @throws ApiException Thrown if the API call fails. + */ + public function setIamPolicy(SetIamPolicyRequest $request, array $callOptions = []): Policy + { + return $this->startApiCall('SetIamPolicy', $request, $callOptions)->wait(); + } + + /** + * Subscribes to a listing. + * + * Currently, with Analytics Hub, you can create listings that + * reference only BigQuery datasets. + * Upon subscription to a listing for a BigQuery dataset, Analytics Hub + * creates a linked dataset in the subscriber's project. + * + * The async variant is {@see self::subscribeListingAsync()} . + * + * @param SubscribeListingRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return SubscribeListingResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function subscribeListing(SubscribeListingRequest $request, array $callOptions = []): SubscribeListingResponse + { + return $this->startApiCall('SubscribeListing', $request, $callOptions)->wait(); + } + + /** + * Returns the permissions that a caller has. + * + * The async variant is {@see self::testIamPermissionsAsync()} . + * + * @param TestIamPermissionsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return TestIamPermissionsResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function testIamPermissions(TestIamPermissionsRequest $request, array $callOptions = []): TestIamPermissionsResponse + { + return $this->startApiCall('TestIamPermissions', $request, $callOptions)->wait(); + } + + /** + * Updates an existing data exchange. + * + * The async variant is {@see self::updateDataExchangeAsync()} . + * + * @param UpdateDataExchangeRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return DataExchange + * + * @throws ApiException Thrown if the API call fails. + */ + public function updateDataExchange(UpdateDataExchangeRequest $request, array $callOptions = []): DataExchange + { + return $this->startApiCall('UpdateDataExchange', $request, $callOptions)->wait(); + } + + /** + * Updates an existing listing. + * + * The async variant is {@see self::updateListingAsync()} . + * + * @param UpdateListingRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Listing + * + * @throws ApiException Thrown if the API call fails. + */ + public function updateListing(UpdateListingRequest $request, array $callOptions = []): Listing + { + return $this->startApiCall('UpdateListing', $request, $callOptions)->wait(); + } +} diff --git a/BigQueryAnalyticsHub/src/V1/CreateDataExchangeRequest.php b/BigQueryAnalyticsHub/src/V1/CreateDataExchangeRequest.php index 4f51f1b4aa16..38bf78819841 100644 --- a/BigQueryAnalyticsHub/src/V1/CreateDataExchangeRequest.php +++ b/BigQueryAnalyticsHub/src/V1/CreateDataExchangeRequest.php @@ -39,6 +39,23 @@ class CreateDataExchangeRequest extends \Google\Protobuf\Internal\Message */ private $data_exchange = null; + /** + * @param string $parent Required. The parent resource path of the data exchange. + * e.g. `projects/myproject/locations/US`. Please see + * {@see AnalyticsHubServiceClient::locationName()} for help formatting this field. + * @param \Google\Cloud\BigQuery\AnalyticsHub\V1\DataExchange $dataExchange Required. The data exchange to create. + * + * @return \Google\Cloud\BigQuery\AnalyticsHub\V1\CreateDataExchangeRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\BigQuery\AnalyticsHub\V1\DataExchange $dataExchange): self + { + return (new self()) + ->setParent($parent) + ->setDataExchange($dataExchange); + } + /** * Constructor. * diff --git a/BigQueryAnalyticsHub/src/V1/CreateListingRequest.php b/BigQueryAnalyticsHub/src/V1/CreateListingRequest.php index 365c5351a9a7..cc31064d34d0 100644 --- a/BigQueryAnalyticsHub/src/V1/CreateListingRequest.php +++ b/BigQueryAnalyticsHub/src/V1/CreateListingRequest.php @@ -39,6 +39,23 @@ class CreateListingRequest extends \Google\Protobuf\Internal\Message */ private $listing = null; + /** + * @param string $parent Required. The parent resource path of the listing. + * e.g. `projects/myproject/locations/US/dataExchanges/123`. Please see + * {@see AnalyticsHubServiceClient::dataExchangeName()} for help formatting this field. + * @param \Google\Cloud\BigQuery\AnalyticsHub\V1\Listing $listing Required. The listing to create. + * + * @return \Google\Cloud\BigQuery\AnalyticsHub\V1\CreateListingRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\BigQuery\AnalyticsHub\V1\Listing $listing): self + { + return (new self()) + ->setParent($parent) + ->setListing($listing); + } + /** * Constructor. * diff --git a/BigQueryAnalyticsHub/src/V1/DeleteDataExchangeRequest.php b/BigQueryAnalyticsHub/src/V1/DeleteDataExchangeRequest.php index 13f27d9f4119..645a5cdf454c 100644 --- a/BigQueryAnalyticsHub/src/V1/DeleteDataExchangeRequest.php +++ b/BigQueryAnalyticsHub/src/V1/DeleteDataExchangeRequest.php @@ -23,6 +23,21 @@ class DeleteDataExchangeRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The full name of the data exchange resource that you want to delete. + * For example, `projects/myproject/locations/US/dataExchanges/123`. Please see + * {@see AnalyticsHubServiceClient::dataExchangeName()} for help formatting this field. + * + * @return \Google\Cloud\BigQuery\AnalyticsHub\V1\DeleteDataExchangeRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/BigQueryAnalyticsHub/src/V1/DeleteListingRequest.php b/BigQueryAnalyticsHub/src/V1/DeleteListingRequest.php index 3277cbf12b06..007377c6cba8 100644 --- a/BigQueryAnalyticsHub/src/V1/DeleteListingRequest.php +++ b/BigQueryAnalyticsHub/src/V1/DeleteListingRequest.php @@ -23,6 +23,21 @@ class DeleteListingRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. Resource name of the listing to delete. + * e.g. `projects/myproject/locations/US/dataExchanges/123/listings/456`. Please see + * {@see AnalyticsHubServiceClient::listingName()} for help formatting this field. + * + * @return \Google\Cloud\BigQuery\AnalyticsHub\V1\DeleteListingRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/BigQueryAnalyticsHub/src/V1/GetDataExchangeRequest.php b/BigQueryAnalyticsHub/src/V1/GetDataExchangeRequest.php index 8c77999f419a..4214a434e4a7 100644 --- a/BigQueryAnalyticsHub/src/V1/GetDataExchangeRequest.php +++ b/BigQueryAnalyticsHub/src/V1/GetDataExchangeRequest.php @@ -23,6 +23,21 @@ class GetDataExchangeRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The resource name of the data exchange. + * e.g. `projects/myproject/locations/US/dataExchanges/123`. Please see + * {@see AnalyticsHubServiceClient::dataExchangeName()} for help formatting this field. + * + * @return \Google\Cloud\BigQuery\AnalyticsHub\V1\GetDataExchangeRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/BigQueryAnalyticsHub/src/V1/GetListingRequest.php b/BigQueryAnalyticsHub/src/V1/GetListingRequest.php index 918563852d9a..f98730bac8cc 100644 --- a/BigQueryAnalyticsHub/src/V1/GetListingRequest.php +++ b/BigQueryAnalyticsHub/src/V1/GetListingRequest.php @@ -23,6 +23,21 @@ class GetListingRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The resource name of the listing. + * e.g. `projects/myproject/locations/US/dataExchanges/123/listings/456`. Please see + * {@see AnalyticsHubServiceClient::listingName()} for help formatting this field. + * + * @return \Google\Cloud\BigQuery\AnalyticsHub\V1\GetListingRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/BigQueryAnalyticsHub/src/V1/ListDataExchangesRequest.php b/BigQueryAnalyticsHub/src/V1/ListDataExchangesRequest.php index 49ef88f753c5..7d079cef61ed 100644 --- a/BigQueryAnalyticsHub/src/V1/ListDataExchangesRequest.php +++ b/BigQueryAnalyticsHub/src/V1/ListDataExchangesRequest.php @@ -37,6 +37,21 @@ class ListDataExchangesRequest extends \Google\Protobuf\Internal\Message */ private $page_token = ''; + /** + * @param string $parent Required. The parent resource path of the data exchanges. + * e.g. `projects/myproject/locations/US`. Please see + * {@see AnalyticsHubServiceClient::locationName()} for help formatting this field. + * + * @return \Google\Cloud\BigQuery\AnalyticsHub\V1\ListDataExchangesRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/BigQueryAnalyticsHub/src/V1/ListListingsRequest.php b/BigQueryAnalyticsHub/src/V1/ListListingsRequest.php index 13830a6cd124..9cb0235be004 100644 --- a/BigQueryAnalyticsHub/src/V1/ListListingsRequest.php +++ b/BigQueryAnalyticsHub/src/V1/ListListingsRequest.php @@ -37,6 +37,21 @@ class ListListingsRequest extends \Google\Protobuf\Internal\Message */ private $page_token = ''; + /** + * @param string $parent Required. The parent resource path of the listing. + * e.g. `projects/myproject/locations/US/dataExchanges/123`. Please see + * {@see AnalyticsHubServiceClient::dataExchangeName()} for help formatting this field. + * + * @return \Google\Cloud\BigQuery\AnalyticsHub\V1\ListListingsRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/BigQueryAnalyticsHub/src/V1/ListOrgDataExchangesRequest.php b/BigQueryAnalyticsHub/src/V1/ListOrgDataExchangesRequest.php index 7cf46e10e06f..5a501eae37fc 100644 --- a/BigQueryAnalyticsHub/src/V1/ListOrgDataExchangesRequest.php +++ b/BigQueryAnalyticsHub/src/V1/ListOrgDataExchangesRequest.php @@ -38,6 +38,20 @@ class ListOrgDataExchangesRequest extends \Google\Protobuf\Internal\Message */ private $page_token = ''; + /** + * @param string $organization Required. The organization resource path of the projects containing DataExchanges. + * e.g. `organizations/myorg/locations/US`. + * + * @return \Google\Cloud\BigQuery\AnalyticsHub\V1\ListOrgDataExchangesRequest + * + * @experimental + */ + public static function build(string $organization): self + { + return (new self()) + ->setOrganization($organization); + } + /** * Constructor. * diff --git a/BigQueryAnalyticsHub/src/V1/SubscribeListingRequest.php b/BigQueryAnalyticsHub/src/V1/SubscribeListingRequest.php index dd5ecc9d7411..7fd3af2309c3 100644 --- a/BigQueryAnalyticsHub/src/V1/SubscribeListingRequest.php +++ b/BigQueryAnalyticsHub/src/V1/SubscribeListingRequest.php @@ -24,6 +24,21 @@ class SubscribeListingRequest extends \Google\Protobuf\Internal\Message private $name = ''; protected $destination; + /** + * @param string $name Required. Resource name of the listing that you want to subscribe to. + * e.g. `projects/myproject/locations/US/dataExchanges/123/listings/456`. Please see + * {@see AnalyticsHubServiceClient::listingName()} for help formatting this field. + * + * @return \Google\Cloud\BigQuery\AnalyticsHub\V1\SubscribeListingRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/BigQueryAnalyticsHub/src/V1/UpdateDataExchangeRequest.php b/BigQueryAnalyticsHub/src/V1/UpdateDataExchangeRequest.php index fb965d601126..59db98720136 100644 --- a/BigQueryAnalyticsHub/src/V1/UpdateDataExchangeRequest.php +++ b/BigQueryAnalyticsHub/src/V1/UpdateDataExchangeRequest.php @@ -30,6 +30,23 @@ class UpdateDataExchangeRequest extends \Google\Protobuf\Internal\Message */ private $data_exchange = null; + /** + * @param \Google\Cloud\BigQuery\AnalyticsHub\V1\DataExchange $dataExchange Required. The data exchange to update. + * @param \Google\Protobuf\FieldMask $updateMask Required. Field mask specifies the fields to update in the data exchange + * resource. The fields specified in the + * `updateMask` are relative to the resource and are not a full request. + * + * @return \Google\Cloud\BigQuery\AnalyticsHub\V1\UpdateDataExchangeRequest + * + * @experimental + */ + public static function build(\Google\Cloud\BigQuery\AnalyticsHub\V1\DataExchange $dataExchange, \Google\Protobuf\FieldMask $updateMask): self + { + return (new self()) + ->setDataExchange($dataExchange) + ->setUpdateMask($updateMask); + } + /** * Constructor. * diff --git a/BigQueryAnalyticsHub/src/V1/UpdateListingRequest.php b/BigQueryAnalyticsHub/src/V1/UpdateListingRequest.php index 016f9a3994db..a58e389a72e3 100644 --- a/BigQueryAnalyticsHub/src/V1/UpdateListingRequest.php +++ b/BigQueryAnalyticsHub/src/V1/UpdateListingRequest.php @@ -30,6 +30,23 @@ class UpdateListingRequest extends \Google\Protobuf\Internal\Message */ private $listing = null; + /** + * @param \Google\Cloud\BigQuery\AnalyticsHub\V1\Listing $listing Required. The listing to update. + * @param \Google\Protobuf\FieldMask $updateMask Required. Field mask specifies the fields to update in the listing resource. The + * fields specified in the `updateMask` are relative to the resource and are + * not a full request. + * + * @return \Google\Cloud\BigQuery\AnalyticsHub\V1\UpdateListingRequest + * + * @experimental + */ + public static function build(\Google\Cloud\BigQuery\AnalyticsHub\V1\Listing $listing, \Google\Protobuf\FieldMask $updateMask): self + { + return (new self()) + ->setListing($listing) + ->setUpdateMask($updateMask); + } + /** * Constructor. * diff --git a/BigQueryAnalyticsHub/src/V1/resources/analytics_hub_service_descriptor_config.php b/BigQueryAnalyticsHub/src/V1/resources/analytics_hub_service_descriptor_config.php index f78ed196b2d0..98a467f77d95 100644 --- a/BigQueryAnalyticsHub/src/V1/resources/analytics_hub_service_descriptor_config.php +++ b/BigQueryAnalyticsHub/src/V1/resources/analytics_hub_service_descriptor_config.php @@ -3,6 +3,90 @@ return [ 'interfaces' => [ 'google.cloud.bigquery.analyticshub.v1.AnalyticsHubService' => [ + 'CreateDataExchange' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\BigQuery\AnalyticsHub\V1\DataExchange', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'CreateListing' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\BigQuery\AnalyticsHub\V1\Listing', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'DeleteDataExchange' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Protobuf\GPBEmpty', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'DeleteListing' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Protobuf\GPBEmpty', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetDataExchange' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\BigQuery\AnalyticsHub\V1\DataExchange', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetIamPolicy' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\Policy', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], + ], + 'GetListing' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\BigQuery\AnalyticsHub\V1\Listing', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], 'ListDataExchanges' => [ 'pageStreaming' => [ 'requestPageTokenGetMethod' => 'getPageToken', @@ -12,6 +96,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getDataExchanges', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\BigQuery\AnalyticsHub\V1\ListDataExchangesResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ListListings' => [ 'pageStreaming' => [ @@ -22,6 +116,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getListings', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\BigQuery\AnalyticsHub\V1\ListListingsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ListOrgDataExchanges' => [ 'pageStreaming' => [ @@ -32,6 +136,84 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getDataExchanges', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\BigQuery\AnalyticsHub\V1\ListOrgDataExchangesResponse', + 'headerParams' => [ + [ + 'keyName' => 'organization', + 'fieldAccessors' => [ + 'getOrganization', + ], + ], + ], + ], + 'SetIamPolicy' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\Policy', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], + ], + 'SubscribeListing' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\BigQuery\AnalyticsHub\V1\SubscribeListingResponse', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'TestIamPermissions' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\TestIamPermissionsResponse', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], + ], + 'UpdateDataExchange' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\BigQuery\AnalyticsHub\V1\DataExchange', + 'headerParams' => [ + [ + 'keyName' => 'data_exchange.name', + 'fieldAccessors' => [ + 'getDataExchange', + 'getName', + ], + ], + ], + ], + 'UpdateListing' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\BigQuery\AnalyticsHub\V1\Listing', + 'headerParams' => [ + [ + 'keyName' => 'listing.name', + 'fieldAccessors' => [ + 'getListing', + 'getName', + ], + ], + ], + ], + 'templateMap' => [ + 'dataExchange' => 'projects/{project}/locations/{location}/dataExchanges/{data_exchange}', + 'dataset' => 'projects/{project}/datasets/{dataset}', + 'listing' => 'projects/{project}/locations/{location}/dataExchanges/{data_exchange}/listings/{listing}', + 'location' => 'projects/{project}/locations/{location}', ], ], ], diff --git a/BigQueryAnalyticsHub/tests/Unit/V1/Client/AnalyticsHubServiceClientTest.php b/BigQueryAnalyticsHub/tests/Unit/V1/Client/AnalyticsHubServiceClientTest.php new file mode 100644 index 000000000000..f54f665c0144 --- /dev/null +++ b/BigQueryAnalyticsHub/tests/Unit/V1/Client/AnalyticsHubServiceClientTest.php @@ -0,0 +1,1259 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return AnalyticsHubServiceClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new AnalyticsHubServiceClient($options); + } + + /** @test */ + public function createDataExchangeTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $displayName = 'displayName1615086568'; + $description = 'description-1724546052'; + $primaryContact = 'primaryContact203339491'; + $documentation = 'documentation1587405498'; + $listingCount = 1101038700; + $icon = '121'; + $expectedResponse = new DataExchange(); + $expectedResponse->setName($name); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setDescription($description); + $expectedResponse->setPrimaryContact($primaryContact); + $expectedResponse->setDocumentation($documentation); + $expectedResponse->setListingCount($listingCount); + $expectedResponse->setIcon($icon); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $dataExchangeId = 'dataExchangeId1402219426'; + $dataExchange = new DataExchange(); + $dataExchangeDisplayName = 'dataExchangeDisplayName-1195270080'; + $dataExchange->setDisplayName($dataExchangeDisplayName); + $request = (new CreateDataExchangeRequest()) + ->setParent($formattedParent) + ->setDataExchangeId($dataExchangeId) + ->setDataExchange($dataExchange); + $response = $gapicClient->createDataExchange($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.bigquery.analyticshub.v1.AnalyticsHubService/CreateDataExchange', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getDataExchangeId(); + $this->assertProtobufEquals($dataExchangeId, $actualValue); + $actualValue = $actualRequestObject->getDataExchange(); + $this->assertProtobufEquals($dataExchange, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createDataExchangeExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $dataExchangeId = 'dataExchangeId1402219426'; + $dataExchange = new DataExchange(); + $dataExchangeDisplayName = 'dataExchangeDisplayName-1195270080'; + $dataExchange->setDisplayName($dataExchangeDisplayName); + $request = (new CreateDataExchangeRequest()) + ->setParent($formattedParent) + ->setDataExchangeId($dataExchangeId) + ->setDataExchange($dataExchange); + try { + $gapicClient->createDataExchange($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createListingTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $displayName = 'displayName1615086568'; + $description = 'description-1724546052'; + $primaryContact = 'primaryContact203339491'; + $documentation = 'documentation1587405498'; + $icon = '121'; + $requestAccess = 'requestAccess2059178260'; + $expectedResponse = new Listing(); + $expectedResponse->setName($name); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setDescription($description); + $expectedResponse->setPrimaryContact($primaryContact); + $expectedResponse->setDocumentation($documentation); + $expectedResponse->setIcon($icon); + $expectedResponse->setRequestAccess($requestAccess); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->dataExchangeName('[PROJECT]', '[LOCATION]', '[DATA_EXCHANGE]'); + $listingId = 'listingId988969142'; + $listing = new Listing(); + $listingDisplayName = 'listingDisplayName293456201'; + $listing->setDisplayName($listingDisplayName); + $listingBigqueryDataset = new BigQueryDatasetSource(); + $listing->setBigqueryDataset($listingBigqueryDataset); + $request = (new CreateListingRequest()) + ->setParent($formattedParent) + ->setListingId($listingId) + ->setListing($listing); + $response = $gapicClient->createListing($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.bigquery.analyticshub.v1.AnalyticsHubService/CreateListing', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getListingId(); + $this->assertProtobufEquals($listingId, $actualValue); + $actualValue = $actualRequestObject->getListing(); + $this->assertProtobufEquals($listing, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createListingExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->dataExchangeName('[PROJECT]', '[LOCATION]', '[DATA_EXCHANGE]'); + $listingId = 'listingId988969142'; + $listing = new Listing(); + $listingDisplayName = 'listingDisplayName293456201'; + $listing->setDisplayName($listingDisplayName); + $listingBigqueryDataset = new BigQueryDatasetSource(); + $listing->setBigqueryDataset($listingBigqueryDataset); + $request = (new CreateListingRequest()) + ->setParent($formattedParent) + ->setListingId($listingId) + ->setListing($listing); + try { + $gapicClient->createListing($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteDataExchangeTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new GPBEmpty(); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->dataExchangeName('[PROJECT]', '[LOCATION]', '[DATA_EXCHANGE]'); + $request = (new DeleteDataExchangeRequest()) + ->setName($formattedName); + $gapicClient->deleteDataExchange($request); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.bigquery.analyticshub.v1.AnalyticsHubService/DeleteDataExchange', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteDataExchangeExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->dataExchangeName('[PROJECT]', '[LOCATION]', '[DATA_EXCHANGE]'); + $request = (new DeleteDataExchangeRequest()) + ->setName($formattedName); + try { + $gapicClient->deleteDataExchange($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteListingTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new GPBEmpty(); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->listingName('[PROJECT]', '[LOCATION]', '[DATA_EXCHANGE]', '[LISTING]'); + $request = (new DeleteListingRequest()) + ->setName($formattedName); + $gapicClient->deleteListing($request); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.bigquery.analyticshub.v1.AnalyticsHubService/DeleteListing', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteListingExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->listingName('[PROJECT]', '[LOCATION]', '[DATA_EXCHANGE]', '[LISTING]'); + $request = (new DeleteListingRequest()) + ->setName($formattedName); + try { + $gapicClient->deleteListing($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getDataExchangeTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $displayName = 'displayName1615086568'; + $description = 'description-1724546052'; + $primaryContact = 'primaryContact203339491'; + $documentation = 'documentation1587405498'; + $listingCount = 1101038700; + $icon = '121'; + $expectedResponse = new DataExchange(); + $expectedResponse->setName($name2); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setDescription($description); + $expectedResponse->setPrimaryContact($primaryContact); + $expectedResponse->setDocumentation($documentation); + $expectedResponse->setListingCount($listingCount); + $expectedResponse->setIcon($icon); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->dataExchangeName('[PROJECT]', '[LOCATION]', '[DATA_EXCHANGE]'); + $request = (new GetDataExchangeRequest()) + ->setName($formattedName); + $response = $gapicClient->getDataExchange($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.bigquery.analyticshub.v1.AnalyticsHubService/GetDataExchange', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getDataExchangeExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->dataExchangeName('[PROJECT]', '[LOCATION]', '[DATA_EXCHANGE]'); + $request = (new GetDataExchangeRequest()) + ->setName($formattedName); + try { + $gapicClient->getDataExchange($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getIamPolicyTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $version = 351608024; + $etag = '21'; + $expectedResponse = new Policy(); + $expectedResponse->setVersion($version); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + $response = $gapicClient->getIamPolicy($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.bigquery.analyticshub.v1.AnalyticsHubService/GetIamPolicy', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getIamPolicyExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $resource = 'resource-341064690'; + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + try { + $gapicClient->getIamPolicy($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getListingTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $displayName = 'displayName1615086568'; + $description = 'description-1724546052'; + $primaryContact = 'primaryContact203339491'; + $documentation = 'documentation1587405498'; + $icon = '121'; + $requestAccess = 'requestAccess2059178260'; + $expectedResponse = new Listing(); + $expectedResponse->setName($name2); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setDescription($description); + $expectedResponse->setPrimaryContact($primaryContact); + $expectedResponse->setDocumentation($documentation); + $expectedResponse->setIcon($icon); + $expectedResponse->setRequestAccess($requestAccess); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->listingName('[PROJECT]', '[LOCATION]', '[DATA_EXCHANGE]', '[LISTING]'); + $request = (new GetListingRequest()) + ->setName($formattedName); + $response = $gapicClient->getListing($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.bigquery.analyticshub.v1.AnalyticsHubService/GetListing', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getListingExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->listingName('[PROJECT]', '[LOCATION]', '[DATA_EXCHANGE]', '[LISTING]'); + $request = (new GetListingRequest()) + ->setName($formattedName); + try { + $gapicClient->getListing($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listDataExchangesTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $dataExchangesElement = new DataExchange(); + $dataExchanges = [ + $dataExchangesElement, + ]; + $expectedResponse = new ListDataExchangesResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setDataExchanges($dataExchanges); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListDataExchangesRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listDataExchanges($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getDataExchanges()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.bigquery.analyticshub.v1.AnalyticsHubService/ListDataExchanges', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listDataExchangesExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListDataExchangesRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listDataExchanges($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listListingsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $listingsElement = new Listing(); + $listings = [ + $listingsElement, + ]; + $expectedResponse = new ListListingsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setListings($listings); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->dataExchangeName('[PROJECT]', '[LOCATION]', '[DATA_EXCHANGE]'); + $request = (new ListListingsRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listListings($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getListings()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.bigquery.analyticshub.v1.AnalyticsHubService/ListListings', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listListingsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->dataExchangeName('[PROJECT]', '[LOCATION]', '[DATA_EXCHANGE]'); + $request = (new ListListingsRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listListings($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listOrgDataExchangesTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $dataExchangesElement = new DataExchange(); + $dataExchanges = [ + $dataExchangesElement, + ]; + $expectedResponse = new ListOrgDataExchangesResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setDataExchanges($dataExchanges); + $transport->addResponse($expectedResponse); + // Mock request + $organization = 'organization1178922291'; + $request = (new ListOrgDataExchangesRequest()) + ->setOrganization($organization); + $response = $gapicClient->listOrgDataExchanges($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getDataExchanges()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.bigquery.analyticshub.v1.AnalyticsHubService/ListOrgDataExchanges', $actualFuncCall); + $actualValue = $actualRequestObject->getOrganization(); + $this->assertProtobufEquals($organization, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listOrgDataExchangesExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $organization = 'organization1178922291'; + $request = (new ListOrgDataExchangesRequest()) + ->setOrganization($organization); + try { + $gapicClient->listOrgDataExchanges($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function setIamPolicyTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $version = 351608024; + $etag = '21'; + $expectedResponse = new Policy(); + $expectedResponse->setVersion($version); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $policy = new Policy(); + $request = (new SetIamPolicyRequest()) + ->setResource($resource) + ->setPolicy($policy); + $response = $gapicClient->setIamPolicy($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.bigquery.analyticshub.v1.AnalyticsHubService/SetIamPolicy', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $actualValue = $actualRequestObject->getPolicy(); + $this->assertProtobufEquals($policy, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function setIamPolicyExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $resource = 'resource-341064690'; + $policy = new Policy(); + $request = (new SetIamPolicyRequest()) + ->setResource($resource) + ->setPolicy($policy); + try { + $gapicClient->setIamPolicy($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function subscribeListingTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new SubscribeListingResponse(); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->listingName('[PROJECT]', '[LOCATION]', '[DATA_EXCHANGE]', '[LISTING]'); + $request = (new SubscribeListingRequest()) + ->setName($formattedName); + $response = $gapicClient->subscribeListing($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.bigquery.analyticshub.v1.AnalyticsHubService/SubscribeListing', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function subscribeListingExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->listingName('[PROJECT]', '[LOCATION]', '[DATA_EXCHANGE]', '[LISTING]'); + $request = (new SubscribeListingRequest()) + ->setName($formattedName); + try { + $gapicClient->subscribeListing($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function testIamPermissionsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new TestIamPermissionsResponse(); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $permissions = []; + $request = (new TestIamPermissionsRequest()) + ->setResource($resource) + ->setPermissions($permissions); + $response = $gapicClient->testIamPermissions($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.bigquery.analyticshub.v1.AnalyticsHubService/TestIamPermissions', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $actualValue = $actualRequestObject->getPermissions(); + $this->assertProtobufEquals($permissions, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function testIamPermissionsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $resource = 'resource-341064690'; + $permissions = []; + $request = (new TestIamPermissionsRequest()) + ->setResource($resource) + ->setPermissions($permissions); + try { + $gapicClient->testIamPermissions($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function updateDataExchangeTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $displayName = 'displayName1615086568'; + $description = 'description-1724546052'; + $primaryContact = 'primaryContact203339491'; + $documentation = 'documentation1587405498'; + $listingCount = 1101038700; + $icon = '121'; + $expectedResponse = new DataExchange(); + $expectedResponse->setName($name); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setDescription($description); + $expectedResponse->setPrimaryContact($primaryContact); + $expectedResponse->setDocumentation($documentation); + $expectedResponse->setListingCount($listingCount); + $expectedResponse->setIcon($icon); + $transport->addResponse($expectedResponse); + // Mock request + $updateMask = new FieldMask(); + $dataExchange = new DataExchange(); + $dataExchangeDisplayName = 'dataExchangeDisplayName-1195270080'; + $dataExchange->setDisplayName($dataExchangeDisplayName); + $request = (new UpdateDataExchangeRequest()) + ->setUpdateMask($updateMask) + ->setDataExchange($dataExchange); + $response = $gapicClient->updateDataExchange($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.bigquery.analyticshub.v1.AnalyticsHubService/UpdateDataExchange', $actualFuncCall); + $actualValue = $actualRequestObject->getUpdateMask(); + $this->assertProtobufEquals($updateMask, $actualValue); + $actualValue = $actualRequestObject->getDataExchange(); + $this->assertProtobufEquals($dataExchange, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function updateDataExchangeExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $updateMask = new FieldMask(); + $dataExchange = new DataExchange(); + $dataExchangeDisplayName = 'dataExchangeDisplayName-1195270080'; + $dataExchange->setDisplayName($dataExchangeDisplayName); + $request = (new UpdateDataExchangeRequest()) + ->setUpdateMask($updateMask) + ->setDataExchange($dataExchange); + try { + $gapicClient->updateDataExchange($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function updateListingTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $displayName = 'displayName1615086568'; + $description = 'description-1724546052'; + $primaryContact = 'primaryContact203339491'; + $documentation = 'documentation1587405498'; + $icon = '121'; + $requestAccess = 'requestAccess2059178260'; + $expectedResponse = new Listing(); + $expectedResponse->setName($name); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setDescription($description); + $expectedResponse->setPrimaryContact($primaryContact); + $expectedResponse->setDocumentation($documentation); + $expectedResponse->setIcon($icon); + $expectedResponse->setRequestAccess($requestAccess); + $transport->addResponse($expectedResponse); + // Mock request + $updateMask = new FieldMask(); + $listing = new Listing(); + $listingDisplayName = 'listingDisplayName293456201'; + $listing->setDisplayName($listingDisplayName); + $listingBigqueryDataset = new BigQueryDatasetSource(); + $listing->setBigqueryDataset($listingBigqueryDataset); + $request = (new UpdateListingRequest()) + ->setUpdateMask($updateMask) + ->setListing($listing); + $response = $gapicClient->updateListing($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.bigquery.analyticshub.v1.AnalyticsHubService/UpdateListing', $actualFuncCall); + $actualValue = $actualRequestObject->getUpdateMask(); + $this->assertProtobufEquals($updateMask, $actualValue); + $actualValue = $actualRequestObject->getListing(); + $this->assertProtobufEquals($listing, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function updateListingExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $updateMask = new FieldMask(); + $listing = new Listing(); + $listingDisplayName = 'listingDisplayName293456201'; + $listing->setDisplayName($listingDisplayName); + $listingBigqueryDataset = new BigQueryDatasetSource(); + $listing->setBigqueryDataset($listingBigqueryDataset); + $request = (new UpdateListingRequest()) + ->setUpdateMask($updateMask) + ->setListing($listing); + try { + $gapicClient->updateListing($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createDataExchangeAsyncTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $displayName = 'displayName1615086568'; + $description = 'description-1724546052'; + $primaryContact = 'primaryContact203339491'; + $documentation = 'documentation1587405498'; + $listingCount = 1101038700; + $icon = '121'; + $expectedResponse = new DataExchange(); + $expectedResponse->setName($name); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setDescription($description); + $expectedResponse->setPrimaryContact($primaryContact); + $expectedResponse->setDocumentation($documentation); + $expectedResponse->setListingCount($listingCount); + $expectedResponse->setIcon($icon); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $dataExchangeId = 'dataExchangeId1402219426'; + $dataExchange = new DataExchange(); + $dataExchangeDisplayName = 'dataExchangeDisplayName-1195270080'; + $dataExchange->setDisplayName($dataExchangeDisplayName); + $request = (new CreateDataExchangeRequest()) + ->setParent($formattedParent) + ->setDataExchangeId($dataExchangeId) + ->setDataExchange($dataExchange); + $response = $gapicClient->createDataExchangeAsync($request)->wait(); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.bigquery.analyticshub.v1.AnalyticsHubService/CreateDataExchange', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getDataExchangeId(); + $this->assertProtobufEquals($dataExchangeId, $actualValue); + $actualValue = $actualRequestObject->getDataExchange(); + $this->assertProtobufEquals($dataExchange, $actualValue); + $this->assertTrue($transport->isExhausted()); + } +} diff --git a/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/create_data_exchange.php b/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/create_data_exchange.php index 3827a6f10600..0bd0e04b8172 100644 --- a/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/create_data_exchange.php +++ b/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/create_data_exchange.php @@ -24,7 +24,8 @@ // [START analyticshub_v1beta1_generated_AnalyticsHubService_CreateDataExchange_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BigQuery\DataExchange\V1beta1\AnalyticsHubServiceClient; +use Google\Cloud\BigQuery\DataExchange\V1beta1\Client\AnalyticsHubServiceClient; +use Google\Cloud\BigQuery\DataExchange\V1beta1\CreateDataExchangeRequest; use Google\Cloud\BigQuery\DataExchange\V1beta1\DataExchange; /** @@ -52,18 +53,18 @@ function create_data_exchange_sample( // Create a client. $analyticsHubServiceClient = new AnalyticsHubServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $dataExchange = (new DataExchange()) ->setDisplayName($dataExchangeDisplayName); + $request = (new CreateDataExchangeRequest()) + ->setParent($formattedParent) + ->setDataExchangeId($dataExchangeId) + ->setDataExchange($dataExchange); // Call the API and handle any network failures. try { /** @var DataExchange $response */ - $response = $analyticsHubServiceClient->createDataExchange( - $formattedParent, - $dataExchangeId, - $dataExchange - ); + $response = $analyticsHubServiceClient->createDataExchange($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/create_listing.php b/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/create_listing.php index b2acb0f7b2ec..bcce302a589d 100644 --- a/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/create_listing.php +++ b/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/create_listing.php @@ -24,7 +24,8 @@ // [START analyticshub_v1beta1_generated_AnalyticsHubService_CreateListing_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BigQuery\DataExchange\V1beta1\AnalyticsHubServiceClient; +use Google\Cloud\BigQuery\DataExchange\V1beta1\Client\AnalyticsHubServiceClient; +use Google\Cloud\BigQuery\DataExchange\V1beta1\CreateListingRequest; use Google\Cloud\BigQuery\DataExchange\V1beta1\Listing; use Google\Cloud\BigQuery\DataExchange\V1beta1\Listing\BigQueryDatasetSource; @@ -53,16 +54,20 @@ function create_listing_sample( // Create a client. $analyticsHubServiceClient = new AnalyticsHubServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $listingBigqueryDataset = new BigQueryDatasetSource(); $listing = (new Listing()) ->setBigqueryDataset($listingBigqueryDataset) ->setDisplayName($listingDisplayName); + $request = (new CreateListingRequest()) + ->setParent($formattedParent) + ->setListingId($listingId) + ->setListing($listing); // Call the API and handle any network failures. try { /** @var Listing $response */ - $response = $analyticsHubServiceClient->createListing($formattedParent, $listingId, $listing); + $response = $analyticsHubServiceClient->createListing($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/delete_data_exchange.php b/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/delete_data_exchange.php index aeec0fe345ac..ab45b1c634a9 100644 --- a/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/delete_data_exchange.php +++ b/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/delete_data_exchange.php @@ -24,7 +24,8 @@ // [START analyticshub_v1beta1_generated_AnalyticsHubService_DeleteDataExchange_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BigQuery\DataExchange\V1beta1\AnalyticsHubServiceClient; +use Google\Cloud\BigQuery\DataExchange\V1beta1\Client\AnalyticsHubServiceClient; +use Google\Cloud\BigQuery\DataExchange\V1beta1\DeleteDataExchangeRequest; /** * Deletes an existing data exchange. @@ -38,9 +39,13 @@ function delete_data_exchange_sample(string $formattedName): void // Create a client. $analyticsHubServiceClient = new AnalyticsHubServiceClient(); + // Prepare the request message. + $request = (new DeleteDataExchangeRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { - $analyticsHubServiceClient->deleteDataExchange($formattedName); + $analyticsHubServiceClient->deleteDataExchange($request); printf('Call completed successfully.' . PHP_EOL); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/delete_listing.php b/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/delete_listing.php index 9834f67c5108..921673c1f39c 100644 --- a/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/delete_listing.php +++ b/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/delete_listing.php @@ -24,7 +24,8 @@ // [START analyticshub_v1beta1_generated_AnalyticsHubService_DeleteListing_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BigQuery\DataExchange\V1beta1\AnalyticsHubServiceClient; +use Google\Cloud\BigQuery\DataExchange\V1beta1\Client\AnalyticsHubServiceClient; +use Google\Cloud\BigQuery\DataExchange\V1beta1\DeleteListingRequest; /** * Deletes a listing. @@ -38,9 +39,13 @@ function delete_listing_sample(string $formattedName): void // Create a client. $analyticsHubServiceClient = new AnalyticsHubServiceClient(); + // Prepare the request message. + $request = (new DeleteListingRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { - $analyticsHubServiceClient->deleteListing($formattedName); + $analyticsHubServiceClient->deleteListing($request); printf('Call completed successfully.' . PHP_EOL); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/get_data_exchange.php b/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/get_data_exchange.php index f1fdb09b8cc2..4e0c3eacae46 100644 --- a/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/get_data_exchange.php +++ b/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/get_data_exchange.php @@ -24,8 +24,9 @@ // [START analyticshub_v1beta1_generated_AnalyticsHubService_GetDataExchange_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BigQuery\DataExchange\V1beta1\AnalyticsHubServiceClient; +use Google\Cloud\BigQuery\DataExchange\V1beta1\Client\AnalyticsHubServiceClient; use Google\Cloud\BigQuery\DataExchange\V1beta1\DataExchange; +use Google\Cloud\BigQuery\DataExchange\V1beta1\GetDataExchangeRequest; /** * Gets the details of a data exchange. @@ -39,10 +40,14 @@ function get_data_exchange_sample(string $formattedName): void // Create a client. $analyticsHubServiceClient = new AnalyticsHubServiceClient(); + // Prepare the request message. + $request = (new GetDataExchangeRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var DataExchange $response */ - $response = $analyticsHubServiceClient->getDataExchange($formattedName); + $response = $analyticsHubServiceClient->getDataExchange($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/get_iam_policy.php b/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/get_iam_policy.php index de4a7f4cd2fe..9b5c8745de2c 100644 --- a/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/get_iam_policy.php +++ b/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/get_iam_policy.php @@ -24,7 +24,8 @@ // [START analyticshub_v1beta1_generated_AnalyticsHubService_GetIamPolicy_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BigQuery\DataExchange\V1beta1\AnalyticsHubServiceClient; +use Google\Cloud\BigQuery\DataExchange\V1beta1\Client\AnalyticsHubServiceClient; +use Google\Cloud\Iam\V1\GetIamPolicyRequest; use Google\Cloud\Iam\V1\Policy; /** @@ -38,10 +39,14 @@ function get_iam_policy_sample(string $resource): void // Create a client. $analyticsHubServiceClient = new AnalyticsHubServiceClient(); + // Prepare the request message. + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + // Call the API and handle any network failures. try { /** @var Policy $response */ - $response = $analyticsHubServiceClient->getIamPolicy($resource); + $response = $analyticsHubServiceClient->getIamPolicy($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/get_listing.php b/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/get_listing.php index 4cccf0c00f7e..ab23f134bd88 100644 --- a/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/get_listing.php +++ b/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/get_listing.php @@ -24,7 +24,8 @@ // [START analyticshub_v1beta1_generated_AnalyticsHubService_GetListing_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BigQuery\DataExchange\V1beta1\AnalyticsHubServiceClient; +use Google\Cloud\BigQuery\DataExchange\V1beta1\Client\AnalyticsHubServiceClient; +use Google\Cloud\BigQuery\DataExchange\V1beta1\GetListingRequest; use Google\Cloud\BigQuery\DataExchange\V1beta1\Listing; /** @@ -39,10 +40,14 @@ function get_listing_sample(string $formattedName): void // Create a client. $analyticsHubServiceClient = new AnalyticsHubServiceClient(); + // Prepare the request message. + $request = (new GetListingRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var Listing $response */ - $response = $analyticsHubServiceClient->getListing($formattedName); + $response = $analyticsHubServiceClient->getListing($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/get_location.php b/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/get_location.php index 851fba3d3b5a..cfe2b44be3ac 100644 --- a/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/get_location.php +++ b/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/get_location.php @@ -24,7 +24,8 @@ // [START analyticshub_v1beta1_generated_AnalyticsHubService_GetLocation_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BigQuery\DataExchange\V1beta1\AnalyticsHubServiceClient; +use Google\Cloud\BigQuery\DataExchange\V1beta1\Client\AnalyticsHubServiceClient; +use Google\Cloud\Location\GetLocationRequest; use Google\Cloud\Location\Location; /** @@ -41,10 +42,13 @@ function get_location_sample(): void // Create a client. $analyticsHubServiceClient = new AnalyticsHubServiceClient(); + // Prepare the request message. + $request = new GetLocationRequest(); + // Call the API and handle any network failures. try { /** @var Location $response */ - $response = $analyticsHubServiceClient->getLocation(); + $response = $analyticsHubServiceClient->getLocation($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/list_data_exchanges.php b/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/list_data_exchanges.php index d9c223c836ad..e1c494cef513 100644 --- a/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/list_data_exchanges.php +++ b/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/list_data_exchanges.php @@ -25,8 +25,9 @@ // [START analyticshub_v1beta1_generated_AnalyticsHubService_ListDataExchanges_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; -use Google\Cloud\BigQuery\DataExchange\V1beta1\AnalyticsHubServiceClient; +use Google\Cloud\BigQuery\DataExchange\V1beta1\Client\AnalyticsHubServiceClient; use Google\Cloud\BigQuery\DataExchange\V1beta1\DataExchange; +use Google\Cloud\BigQuery\DataExchange\V1beta1\ListDataExchangesRequest; /** * Lists all data exchanges in a given project and location. @@ -40,10 +41,14 @@ function list_data_exchanges_sample(string $formattedParent): void // Create a client. $analyticsHubServiceClient = new AnalyticsHubServiceClient(); + // Prepare the request message. + $request = (new ListDataExchangesRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $analyticsHubServiceClient->listDataExchanges($formattedParent); + $response = $analyticsHubServiceClient->listDataExchanges($request); /** @var DataExchange $element */ foreach ($response as $element) { diff --git a/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/list_listings.php b/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/list_listings.php index 9d9ed9f58923..768e8d61ab69 100644 --- a/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/list_listings.php +++ b/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/list_listings.php @@ -25,7 +25,8 @@ // [START analyticshub_v1beta1_generated_AnalyticsHubService_ListListings_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; -use Google\Cloud\BigQuery\DataExchange\V1beta1\AnalyticsHubServiceClient; +use Google\Cloud\BigQuery\DataExchange\V1beta1\Client\AnalyticsHubServiceClient; +use Google\Cloud\BigQuery\DataExchange\V1beta1\ListListingsRequest; use Google\Cloud\BigQuery\DataExchange\V1beta1\Listing; /** @@ -40,10 +41,14 @@ function list_listings_sample(string $formattedParent): void // Create a client. $analyticsHubServiceClient = new AnalyticsHubServiceClient(); + // Prepare the request message. + $request = (new ListListingsRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $analyticsHubServiceClient->listListings($formattedParent); + $response = $analyticsHubServiceClient->listListings($request); /** @var Listing $element */ foreach ($response as $element) { diff --git a/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/list_locations.php b/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/list_locations.php index c3216086c69a..9b4637aeb55a 100644 --- a/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/list_locations.php +++ b/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/list_locations.php @@ -25,7 +25,8 @@ // [START analyticshub_v1beta1_generated_AnalyticsHubService_ListLocations_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; -use Google\Cloud\BigQuery\DataExchange\V1beta1\AnalyticsHubServiceClient; +use Google\Cloud\BigQuery\DataExchange\V1beta1\Client\AnalyticsHubServiceClient; +use Google\Cloud\Location\ListLocationsRequest; use Google\Cloud\Location\Location; /** @@ -42,10 +43,13 @@ function list_locations_sample(): void // Create a client. $analyticsHubServiceClient = new AnalyticsHubServiceClient(); + // Prepare the request message. + $request = new ListLocationsRequest(); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $analyticsHubServiceClient->listLocations(); + $response = $analyticsHubServiceClient->listLocations($request); /** @var Location $element */ foreach ($response as $element) { diff --git a/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/list_org_data_exchanges.php b/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/list_org_data_exchanges.php index 365ad26dee49..8610cbfce41e 100644 --- a/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/list_org_data_exchanges.php +++ b/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/list_org_data_exchanges.php @@ -25,8 +25,9 @@ // [START analyticshub_v1beta1_generated_AnalyticsHubService_ListOrgDataExchanges_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; -use Google\Cloud\BigQuery\DataExchange\V1beta1\AnalyticsHubServiceClient; +use Google\Cloud\BigQuery\DataExchange\V1beta1\Client\AnalyticsHubServiceClient; use Google\Cloud\BigQuery\DataExchange\V1beta1\DataExchange; +use Google\Cloud\BigQuery\DataExchange\V1beta1\ListOrgDataExchangesRequest; /** * Lists all data exchanges from projects in a given organization and @@ -40,10 +41,14 @@ function list_org_data_exchanges_sample(string $organization): void // Create a client. $analyticsHubServiceClient = new AnalyticsHubServiceClient(); + // Prepare the request message. + $request = (new ListOrgDataExchangesRequest()) + ->setOrganization($organization); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $analyticsHubServiceClient->listOrgDataExchanges($organization); + $response = $analyticsHubServiceClient->listOrgDataExchanges($request); /** @var DataExchange $element */ foreach ($response as $element) { diff --git a/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/set_iam_policy.php b/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/set_iam_policy.php index 22e83015e4e4..b925d755281a 100644 --- a/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/set_iam_policy.php +++ b/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/set_iam_policy.php @@ -24,8 +24,9 @@ // [START analyticshub_v1beta1_generated_AnalyticsHubService_SetIamPolicy_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BigQuery\DataExchange\V1beta1\AnalyticsHubServiceClient; +use Google\Cloud\BigQuery\DataExchange\V1beta1\Client\AnalyticsHubServiceClient; use Google\Cloud\Iam\V1\Policy; +use Google\Cloud\Iam\V1\SetIamPolicyRequest; /** * Sets the IAM policy. @@ -38,13 +39,16 @@ function set_iam_policy_sample(string $resource): void // Create a client. $analyticsHubServiceClient = new AnalyticsHubServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $policy = new Policy(); + $request = (new SetIamPolicyRequest()) + ->setResource($resource) + ->setPolicy($policy); // Call the API and handle any network failures. try { /** @var Policy $response */ - $response = $analyticsHubServiceClient->setIamPolicy($resource, $policy); + $response = $analyticsHubServiceClient->setIamPolicy($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/subscribe_listing.php b/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/subscribe_listing.php index 92190185e888..9e9df85fea17 100644 --- a/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/subscribe_listing.php +++ b/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/subscribe_listing.php @@ -24,7 +24,8 @@ // [START analyticshub_v1beta1_generated_AnalyticsHubService_SubscribeListing_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BigQuery\DataExchange\V1beta1\AnalyticsHubServiceClient; +use Google\Cloud\BigQuery\DataExchange\V1beta1\Client\AnalyticsHubServiceClient; +use Google\Cloud\BigQuery\DataExchange\V1beta1\SubscribeListingRequest; use Google\Cloud\BigQuery\DataExchange\V1beta1\SubscribeListingResponse; /** @@ -44,10 +45,14 @@ function subscribe_listing_sample(string $formattedName): void // Create a client. $analyticsHubServiceClient = new AnalyticsHubServiceClient(); + // Prepare the request message. + $request = (new SubscribeListingRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var SubscribeListingResponse $response */ - $response = $analyticsHubServiceClient->subscribeListing($formattedName); + $response = $analyticsHubServiceClient->subscribeListing($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/test_iam_permissions.php b/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/test_iam_permissions.php index acccc5b50538..e02781360407 100644 --- a/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/test_iam_permissions.php +++ b/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/test_iam_permissions.php @@ -24,7 +24,8 @@ // [START analyticshub_v1beta1_generated_AnalyticsHubService_TestIamPermissions_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BigQuery\DataExchange\V1beta1\AnalyticsHubServiceClient; +use Google\Cloud\BigQuery\DataExchange\V1beta1\Client\AnalyticsHubServiceClient; +use Google\Cloud\Iam\V1\TestIamPermissionsRequest; use Google\Cloud\Iam\V1\TestIamPermissionsResponse; /** @@ -42,13 +43,16 @@ function test_iam_permissions_sample(string $resource, string $permissionsElemen // Create a client. $analyticsHubServiceClient = new AnalyticsHubServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $permissions = [$permissionsElement,]; + $request = (new TestIamPermissionsRequest()) + ->setResource($resource) + ->setPermissions($permissions); // Call the API and handle any network failures. try { /** @var TestIamPermissionsResponse $response */ - $response = $analyticsHubServiceClient->testIamPermissions($resource, $permissions); + $response = $analyticsHubServiceClient->testIamPermissions($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/update_data_exchange.php b/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/update_data_exchange.php index 45dd39703a6d..f8c2554fd1d9 100644 --- a/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/update_data_exchange.php +++ b/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/update_data_exchange.php @@ -24,8 +24,9 @@ // [START analyticshub_v1beta1_generated_AnalyticsHubService_UpdateDataExchange_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BigQuery\DataExchange\V1beta1\AnalyticsHubServiceClient; +use Google\Cloud\BigQuery\DataExchange\V1beta1\Client\AnalyticsHubServiceClient; use Google\Cloud\BigQuery\DataExchange\V1beta1\DataExchange; +use Google\Cloud\BigQuery\DataExchange\V1beta1\UpdateDataExchangeRequest; use Google\Protobuf\FieldMask; /** @@ -42,15 +43,18 @@ function update_data_exchange_sample(string $dataExchangeDisplayName): void // Create a client. $analyticsHubServiceClient = new AnalyticsHubServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $updateMask = new FieldMask(); $dataExchange = (new DataExchange()) ->setDisplayName($dataExchangeDisplayName); + $request = (new UpdateDataExchangeRequest()) + ->setUpdateMask($updateMask) + ->setDataExchange($dataExchange); // Call the API and handle any network failures. try { /** @var DataExchange $response */ - $response = $analyticsHubServiceClient->updateDataExchange($updateMask, $dataExchange); + $response = $analyticsHubServiceClient->updateDataExchange($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/update_listing.php b/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/update_listing.php index cb723bee27a8..2b4c4b8a60f4 100644 --- a/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/update_listing.php +++ b/BigQueryDataExchange/samples/V1beta1/AnalyticsHubServiceClient/update_listing.php @@ -24,9 +24,10 @@ // [START analyticshub_v1beta1_generated_AnalyticsHubService_UpdateListing_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BigQuery\DataExchange\V1beta1\AnalyticsHubServiceClient; +use Google\Cloud\BigQuery\DataExchange\V1beta1\Client\AnalyticsHubServiceClient; use Google\Cloud\BigQuery\DataExchange\V1beta1\Listing; use Google\Cloud\BigQuery\DataExchange\V1beta1\Listing\BigQueryDatasetSource; +use Google\Cloud\BigQuery\DataExchange\V1beta1\UpdateListingRequest; use Google\Protobuf\FieldMask; /** @@ -43,17 +44,20 @@ function update_listing_sample(string $listingDisplayName): void // Create a client. $analyticsHubServiceClient = new AnalyticsHubServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $updateMask = new FieldMask(); $listingBigqueryDataset = new BigQueryDatasetSource(); $listing = (new Listing()) ->setBigqueryDataset($listingBigqueryDataset) ->setDisplayName($listingDisplayName); + $request = (new UpdateListingRequest()) + ->setUpdateMask($updateMask) + ->setListing($listing); // Call the API and handle any network failures. try { /** @var Listing $response */ - $response = $analyticsHubServiceClient->updateListing($updateMask, $listing); + $response = $analyticsHubServiceClient->updateListing($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BigQueryDataExchange/src/V1beta1/Client/AnalyticsHubServiceClient.php b/BigQueryDataExchange/src/V1beta1/Client/AnalyticsHubServiceClient.php new file mode 100644 index 000000000000..c083caaae50b --- /dev/null +++ b/BigQueryDataExchange/src/V1beta1/Client/AnalyticsHubServiceClient.php @@ -0,0 +1,42 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/analytics_hub_service_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/analytics_hub_service_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/analytics_hub_service_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/analytics_hub_service_rest_client_config.php', + ], + ], + ]; + } + + /** + * Formats a string containing the fully-qualified path to represent a + * data_exchange resource. + * + * @param string $project + * @param string $location + * @param string $dataExchange + * + * @return string The formatted data_exchange resource. + * + * @experimental + */ + public static function dataExchangeName(string $project, string $location, string $dataExchange): string + { + return self::getPathTemplate('dataExchange')->render([ + 'project' => $project, + 'location' => $location, + 'data_exchange' => $dataExchange, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a dataset + * resource. + * + * @param string $project + * @param string $dataset + * + * @return string The formatted dataset resource. + * + * @experimental + */ + public static function datasetName(string $project, string $dataset): string + { + return self::getPathTemplate('dataset')->render([ + 'project' => $project, + 'dataset' => $dataset, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a listing + * resource. + * + * @param string $project + * @param string $location + * @param string $dataExchange + * @param string $listing + * + * @return string The formatted listing resource. + * + * @experimental + */ + public static function listingName(string $project, string $location, string $dataExchange, string $listing): string + { + return self::getPathTemplate('listing')->render([ + 'project' => $project, + 'location' => $location, + 'data_exchange' => $dataExchange, + 'listing' => $listing, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a location + * resource. + * + * @param string $project + * @param string $location + * + * @return string The formatted location resource. + * + * @experimental + */ + public static function locationName(string $project, string $location): string + { + return self::getPathTemplate('location')->render([ + 'project' => $project, + 'location' => $location, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * Template: Pattern + * - dataExchange: projects/{project}/locations/{location}/dataExchanges/{data_exchange} + * - dataset: projects/{project}/datasets/{dataset} + * - listing: projects/{project}/locations/{location}/dataExchanges/{data_exchange}/listings/{listing} + * - location: projects/{project}/locations/{location} + * + * The optional $template argument can be supplied to specify a particular pattern, + * and must match one of the templates listed above. If no $template argument is + * provided, or if the $template argument does not match one of the templates + * listed, then parseName will check each of the supported templates, and return + * the first match. + * + * @param string $formattedName The formatted name string + * @param string $template Optional name of template to match + * + * @return array An associative array from name component IDs to component values. + * + * @throws ValidationException If $formattedName could not be matched. + * + * @experimental + */ + public static function parseName(string $formattedName, string $template = null): array + { + return self::parseFormattedName($formattedName, $template); + } + + /** + * Constructor. + * + * @param array $options { + * Optional. Options for configuring the service API wrapper. + * + * @type string $apiEndpoint + * The address of the API remote host. May optionally include the port, formatted + * as ":". Default 'analyticshub.googleapis.com:443'. + * @type string|array|FetchAuthTokenInterface|CredentialsWrapper $credentials + * The credentials to be used by the client to authorize API calls. This option + * accepts either a path to a credentials file, or a decoded credentials file as a + * PHP array. + * *Advanced usage*: In addition, this option can also accept a pre-constructed + * {@see \Google\Auth\FetchAuthTokenInterface} object or + * {@see \Google\ApiCore\CredentialsWrapper} object. Note that when one of these + * objects are provided, any settings in $credentialsConfig will be ignored. + * @type array $credentialsConfig + * Options used to configure credentials, including auth token caching, for the + * client. For a full list of supporting configuration options, see + * {@see \Google\ApiCore\CredentialsWrapper::build()} . + * @type bool $disableRetries + * Determines whether or not retries defined by the client configuration should be + * disabled. Defaults to `false`. + * @type string|array $clientConfig + * Client method configuration, including retry settings. This option can be either + * a path to a JSON file, or a PHP array containing the decoded JSON data. By + * default this settings points to the default client config file, which is + * provided in the resources folder. + * @type string|TransportInterface $transport + * The transport used for executing network requests. May be either the string + * `rest` or `grpc`. Defaults to `grpc` if gRPC support is detected on the system. + * *Advanced usage*: Additionally, it is possible to pass in an already + * instantiated {@see \Google\ApiCore\Transport\TransportInterface} object. Note + * that when this object is provided, any settings in $transportConfig, and any + * $apiEndpoint setting, will be ignored. + * @type array $transportConfig + * Configuration options that will be used to construct the transport. Options for + * each supported transport type should be passed in a key for that transport. For + * example: + * $transportConfig = [ + * 'grpc' => [...], + * 'rest' => [...], + * ]; + * See the {@see \Google\ApiCore\Transport\GrpcTransport::build()} and + * {@see \Google\ApiCore\Transport\RestTransport::build()} methods for the + * supported options. + * @type callable $clientCertSource + * A callable which returns the client cert as a string. This can be used to + * provide a certificate and private key to the transport layer for mTLS. + * } + * + * @throws ValidationException + * + * @experimental + */ + public function __construct(array $options = []) + { + $clientOptions = $this->buildClientOptions($options); + $this->setClientOptions($clientOptions); + } + + /** Handles execution of the async variants for each documented method. */ + public function __call($method, $args) + { + if (substr($method, -5) !== 'Async') { + trigger_error('Call to undefined method ' . __CLASS__ . "::$method()", E_USER_ERROR); + } + + array_unshift($args, substr($method, 0, -5)); + return call_user_func_array([$this, 'startAsyncCall'], $args); + } + + /** + * Creates a new data exchange. + * + * The async variant is {@see self::createDataExchangeAsync()} . + * + * @param CreateDataExchangeRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return DataExchange + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function createDataExchange(CreateDataExchangeRequest $request, array $callOptions = []): DataExchange + { + return $this->startApiCall('CreateDataExchange', $request, $callOptions)->wait(); + } + + /** + * Creates a new listing. + * + * The async variant is {@see self::createListingAsync()} . + * + * @param CreateListingRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Listing + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function createListing(CreateListingRequest $request, array $callOptions = []): Listing + { + return $this->startApiCall('CreateListing', $request, $callOptions)->wait(); + } + + /** + * Deletes an existing data exchange. + * + * The async variant is {@see self::deleteDataExchangeAsync()} . + * + * @param DeleteDataExchangeRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function deleteDataExchange(DeleteDataExchangeRequest $request, array $callOptions = []): void + { + $this->startApiCall('DeleteDataExchange', $request, $callOptions)->wait(); + } + + /** + * Deletes a listing. + * + * The async variant is {@see self::deleteListingAsync()} . + * + * @param DeleteListingRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function deleteListing(DeleteListingRequest $request, array $callOptions = []): void + { + $this->startApiCall('DeleteListing', $request, $callOptions)->wait(); + } + + /** + * Gets the details of a data exchange. + * + * The async variant is {@see self::getDataExchangeAsync()} . + * + * @param GetDataExchangeRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return DataExchange + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function getDataExchange(GetDataExchangeRequest $request, array $callOptions = []): DataExchange + { + return $this->startApiCall('GetDataExchange', $request, $callOptions)->wait(); + } + + /** + * Gets the IAM policy. + * + * The async variant is {@see self::getIamPolicyAsync()} . + * + * @param GetIamPolicyRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Policy + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function getIamPolicy(GetIamPolicyRequest $request, array $callOptions = []): Policy + { + return $this->startApiCall('GetIamPolicy', $request, $callOptions)->wait(); + } + + /** + * Gets the details of a listing. + * + * The async variant is {@see self::getListingAsync()} . + * + * @param GetListingRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Listing + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function getListing(GetListingRequest $request, array $callOptions = []): Listing + { + return $this->startApiCall('GetListing', $request, $callOptions)->wait(); + } + + /** + * Lists all data exchanges in a given project and location. + * + * The async variant is {@see self::listDataExchangesAsync()} . + * + * @param ListDataExchangesRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function listDataExchanges(ListDataExchangesRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListDataExchanges', $request, $callOptions); + } + + /** + * Lists all listings in a given project and location. + * + * The async variant is {@see self::listListingsAsync()} . + * + * @param ListListingsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function listListings(ListListingsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListListings', $request, $callOptions); + } + + /** + * Lists all data exchanges from projects in a given organization and + * location. + * + * The async variant is {@see self::listOrgDataExchangesAsync()} . + * + * @param ListOrgDataExchangesRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function listOrgDataExchanges(ListOrgDataExchangesRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListOrgDataExchanges', $request, $callOptions); + } + + /** + * Sets the IAM policy. + * + * The async variant is {@see self::setIamPolicyAsync()} . + * + * @param SetIamPolicyRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Policy + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function setIamPolicy(SetIamPolicyRequest $request, array $callOptions = []): Policy + { + return $this->startApiCall('SetIamPolicy', $request, $callOptions)->wait(); + } + + /** + * Subscribes to a listing. + * + * Currently, with Analytics Hub, you can create listings that + * reference only BigQuery datasets. + * Upon subscription to a listing for a BigQuery dataset, Analytics Hub + * creates a linked dataset in the subscriber's project. + * + * The async variant is {@see self::subscribeListingAsync()} . + * + * @param SubscribeListingRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return SubscribeListingResponse + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function subscribeListing(SubscribeListingRequest $request, array $callOptions = []): SubscribeListingResponse + { + return $this->startApiCall('SubscribeListing', $request, $callOptions)->wait(); + } + + /** + * Returns the permissions that a caller has. + * + * The async variant is {@see self::testIamPermissionsAsync()} . + * + * @param TestIamPermissionsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return TestIamPermissionsResponse + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function testIamPermissions(TestIamPermissionsRequest $request, array $callOptions = []): TestIamPermissionsResponse + { + return $this->startApiCall('TestIamPermissions', $request, $callOptions)->wait(); + } + + /** + * Updates an existing data exchange. + * + * The async variant is {@see self::updateDataExchangeAsync()} . + * + * @param UpdateDataExchangeRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return DataExchange + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function updateDataExchange(UpdateDataExchangeRequest $request, array $callOptions = []): DataExchange + { + return $this->startApiCall('UpdateDataExchange', $request, $callOptions)->wait(); + } + + /** + * Updates an existing listing. + * + * The async variant is {@see self::updateListingAsync()} . + * + * @param UpdateListingRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Listing + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function updateListing(UpdateListingRequest $request, array $callOptions = []): Listing + { + return $this->startApiCall('UpdateListing', $request, $callOptions)->wait(); + } + + /** + * Gets information about a location. + * + * The async variant is {@see self::getLocationAsync()} . + * + * @param GetLocationRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Location + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function getLocation(GetLocationRequest $request, array $callOptions = []): Location + { + return $this->startApiCall('GetLocation', $request, $callOptions)->wait(); + } + + /** + * Lists information about the supported locations for this service. + * + * The async variant is {@see self::listLocationsAsync()} . + * + * @param ListLocationsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function listLocations(ListLocationsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListLocations', $request, $callOptions); + } +} diff --git a/BigQueryDataExchange/src/V1beta1/CreateDataExchangeRequest.php b/BigQueryDataExchange/src/V1beta1/CreateDataExchangeRequest.php index f65b8586a31e..6ac362075528 100644 --- a/BigQueryDataExchange/src/V1beta1/CreateDataExchangeRequest.php +++ b/BigQueryDataExchange/src/V1beta1/CreateDataExchangeRequest.php @@ -39,6 +39,23 @@ class CreateDataExchangeRequest extends \Google\Protobuf\Internal\Message */ private $data_exchange = null; + /** + * @param string $parent Required. The parent resource path of the data exchange. + * e.g. `projects/myproject/locations/US`. Please see + * {@see AnalyticsHubServiceClient::locationName()} for help formatting this field. + * @param \Google\Cloud\BigQuery\DataExchange\V1beta1\DataExchange $dataExchange Required. The data exchange to create. + * + * @return \Google\Cloud\BigQuery\DataExchange\V1beta1\CreateDataExchangeRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\BigQuery\DataExchange\V1beta1\DataExchange $dataExchange): self + { + return (new self()) + ->setParent($parent) + ->setDataExchange($dataExchange); + } + /** * Constructor. * diff --git a/BigQueryDataExchange/src/V1beta1/CreateListingRequest.php b/BigQueryDataExchange/src/V1beta1/CreateListingRequest.php index da073dbf82dd..3c0c0101a785 100644 --- a/BigQueryDataExchange/src/V1beta1/CreateListingRequest.php +++ b/BigQueryDataExchange/src/V1beta1/CreateListingRequest.php @@ -39,6 +39,23 @@ class CreateListingRequest extends \Google\Protobuf\Internal\Message */ private $listing = null; + /** + * @param string $parent Required. The parent resource path of the listing. + * e.g. `projects/myproject/locations/US/dataExchanges/123`. Please see + * {@see AnalyticsHubServiceClient::dataExchangeName()} for help formatting this field. + * @param \Google\Cloud\BigQuery\DataExchange\V1beta1\Listing $listing Required. The listing to create. + * + * @return \Google\Cloud\BigQuery\DataExchange\V1beta1\CreateListingRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\BigQuery\DataExchange\V1beta1\Listing $listing): self + { + return (new self()) + ->setParent($parent) + ->setListing($listing); + } + /** * Constructor. * diff --git a/BigQueryDataExchange/src/V1beta1/DeleteDataExchangeRequest.php b/BigQueryDataExchange/src/V1beta1/DeleteDataExchangeRequest.php index defca3b99d75..c00cf4a55c8b 100644 --- a/BigQueryDataExchange/src/V1beta1/DeleteDataExchangeRequest.php +++ b/BigQueryDataExchange/src/V1beta1/DeleteDataExchangeRequest.php @@ -23,6 +23,21 @@ class DeleteDataExchangeRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The full name of the data exchange resource that you want to delete. + * For example, `projects/myproject/locations/US/dataExchanges/123`. Please see + * {@see AnalyticsHubServiceClient::dataExchangeName()} for help formatting this field. + * + * @return \Google\Cloud\BigQuery\DataExchange\V1beta1\DeleteDataExchangeRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/BigQueryDataExchange/src/V1beta1/DeleteListingRequest.php b/BigQueryDataExchange/src/V1beta1/DeleteListingRequest.php index ee922b4891a9..c8456aa21f01 100644 --- a/BigQueryDataExchange/src/V1beta1/DeleteListingRequest.php +++ b/BigQueryDataExchange/src/V1beta1/DeleteListingRequest.php @@ -23,6 +23,21 @@ class DeleteListingRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. Resource name of the listing to delete. + * e.g. `projects/myproject/locations/US/dataExchanges/123/listings/456`. Please see + * {@see AnalyticsHubServiceClient::listingName()} for help formatting this field. + * + * @return \Google\Cloud\BigQuery\DataExchange\V1beta1\DeleteListingRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/BigQueryDataExchange/src/V1beta1/GetDataExchangeRequest.php b/BigQueryDataExchange/src/V1beta1/GetDataExchangeRequest.php index c18fa247730f..33f3dcbd526d 100644 --- a/BigQueryDataExchange/src/V1beta1/GetDataExchangeRequest.php +++ b/BigQueryDataExchange/src/V1beta1/GetDataExchangeRequest.php @@ -23,6 +23,21 @@ class GetDataExchangeRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The resource name of the data exchange. + * e.g. `projects/myproject/locations/US/dataExchanges/123`. Please see + * {@see AnalyticsHubServiceClient::dataExchangeName()} for help formatting this field. + * + * @return \Google\Cloud\BigQuery\DataExchange\V1beta1\GetDataExchangeRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/BigQueryDataExchange/src/V1beta1/GetListingRequest.php b/BigQueryDataExchange/src/V1beta1/GetListingRequest.php index 18a68b81d0cc..f93cd882e7d8 100644 --- a/BigQueryDataExchange/src/V1beta1/GetListingRequest.php +++ b/BigQueryDataExchange/src/V1beta1/GetListingRequest.php @@ -23,6 +23,21 @@ class GetListingRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The resource name of the listing. + * e.g. `projects/myproject/locations/US/dataExchanges/123/listings/456`. Please see + * {@see AnalyticsHubServiceClient::listingName()} for help formatting this field. + * + * @return \Google\Cloud\BigQuery\DataExchange\V1beta1\GetListingRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/BigQueryDataExchange/src/V1beta1/ListDataExchangesRequest.php b/BigQueryDataExchange/src/V1beta1/ListDataExchangesRequest.php index 8a9ac9fdd945..1aa0115fd49c 100644 --- a/BigQueryDataExchange/src/V1beta1/ListDataExchangesRequest.php +++ b/BigQueryDataExchange/src/V1beta1/ListDataExchangesRequest.php @@ -37,6 +37,21 @@ class ListDataExchangesRequest extends \Google\Protobuf\Internal\Message */ private $page_token = ''; + /** + * @param string $parent Required. The parent resource path of the data exchanges. + * e.g. `projects/myproject/locations/US`. Please see + * {@see AnalyticsHubServiceClient::locationName()} for help formatting this field. + * + * @return \Google\Cloud\BigQuery\DataExchange\V1beta1\ListDataExchangesRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/BigQueryDataExchange/src/V1beta1/ListListingsRequest.php b/BigQueryDataExchange/src/V1beta1/ListListingsRequest.php index f8db88544b26..406f8b017c53 100644 --- a/BigQueryDataExchange/src/V1beta1/ListListingsRequest.php +++ b/BigQueryDataExchange/src/V1beta1/ListListingsRequest.php @@ -37,6 +37,21 @@ class ListListingsRequest extends \Google\Protobuf\Internal\Message */ private $page_token = ''; + /** + * @param string $parent Required. The parent resource path of the listing. + * e.g. `projects/myproject/locations/US/dataExchanges/123`. Please see + * {@see AnalyticsHubServiceClient::dataExchangeName()} for help formatting this field. + * + * @return \Google\Cloud\BigQuery\DataExchange\V1beta1\ListListingsRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/BigQueryDataExchange/src/V1beta1/ListOrgDataExchangesRequest.php b/BigQueryDataExchange/src/V1beta1/ListOrgDataExchangesRequest.php index 2cee4efe2c24..b9388b42cd0f 100644 --- a/BigQueryDataExchange/src/V1beta1/ListOrgDataExchangesRequest.php +++ b/BigQueryDataExchange/src/V1beta1/ListOrgDataExchangesRequest.php @@ -38,6 +38,20 @@ class ListOrgDataExchangesRequest extends \Google\Protobuf\Internal\Message */ private $page_token = ''; + /** + * @param string $organization Required. The organization resource path of the projects containing DataExchanges. + * e.g. `organizations/myorg/locations/US`. + * + * @return \Google\Cloud\BigQuery\DataExchange\V1beta1\ListOrgDataExchangesRequest + * + * @experimental + */ + public static function build(string $organization): self + { + return (new self()) + ->setOrganization($organization); + } + /** * Constructor. * diff --git a/BigQueryDataExchange/src/V1beta1/SubscribeListingRequest.php b/BigQueryDataExchange/src/V1beta1/SubscribeListingRequest.php index 132f28d879e6..3735bf42a546 100644 --- a/BigQueryDataExchange/src/V1beta1/SubscribeListingRequest.php +++ b/BigQueryDataExchange/src/V1beta1/SubscribeListingRequest.php @@ -24,6 +24,21 @@ class SubscribeListingRequest extends \Google\Protobuf\Internal\Message private $name = ''; protected $destination; + /** + * @param string $name Required. Resource name of the listing that you want to subscribe to. + * e.g. `projects/myproject/locations/US/dataExchanges/123/listings/456`. Please see + * {@see AnalyticsHubServiceClient::listingName()} for help formatting this field. + * + * @return \Google\Cloud\BigQuery\DataExchange\V1beta1\SubscribeListingRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/BigQueryDataExchange/src/V1beta1/UpdateDataExchangeRequest.php b/BigQueryDataExchange/src/V1beta1/UpdateDataExchangeRequest.php index 344c71a64f39..a9013098043d 100644 --- a/BigQueryDataExchange/src/V1beta1/UpdateDataExchangeRequest.php +++ b/BigQueryDataExchange/src/V1beta1/UpdateDataExchangeRequest.php @@ -30,6 +30,23 @@ class UpdateDataExchangeRequest extends \Google\Protobuf\Internal\Message */ private $data_exchange = null; + /** + * @param \Google\Cloud\BigQuery\DataExchange\V1beta1\DataExchange $dataExchange Required. The data exchange to update. + * @param \Google\Protobuf\FieldMask $updateMask Required. Field mask specifies the fields to update in the data exchange + * resource. The fields specified in the + * `updateMask` are relative to the resource and are not a full request. + * + * @return \Google\Cloud\BigQuery\DataExchange\V1beta1\UpdateDataExchangeRequest + * + * @experimental + */ + public static function build(\Google\Cloud\BigQuery\DataExchange\V1beta1\DataExchange $dataExchange, \Google\Protobuf\FieldMask $updateMask): self + { + return (new self()) + ->setDataExchange($dataExchange) + ->setUpdateMask($updateMask); + } + /** * Constructor. * diff --git a/BigQueryDataExchange/src/V1beta1/UpdateListingRequest.php b/BigQueryDataExchange/src/V1beta1/UpdateListingRequest.php index 24cc2d2004fb..2c0e43ec44cc 100644 --- a/BigQueryDataExchange/src/V1beta1/UpdateListingRequest.php +++ b/BigQueryDataExchange/src/V1beta1/UpdateListingRequest.php @@ -30,6 +30,23 @@ class UpdateListingRequest extends \Google\Protobuf\Internal\Message */ private $listing = null; + /** + * @param \Google\Cloud\BigQuery\DataExchange\V1beta1\Listing $listing Required. The listing to update. + * @param \Google\Protobuf\FieldMask $updateMask Required. Field mask specifies the fields to update in the listing resource. The + * fields specified in the `updateMask` are relative to the resource and are + * not a full request. + * + * @return \Google\Cloud\BigQuery\DataExchange\V1beta1\UpdateListingRequest + * + * @experimental + */ + public static function build(\Google\Cloud\BigQuery\DataExchange\V1beta1\Listing $listing, \Google\Protobuf\FieldMask $updateMask): self + { + return (new self()) + ->setListing($listing) + ->setUpdateMask($updateMask); + } + /** * Constructor. * diff --git a/BigQueryDataExchange/src/V1beta1/resources/analytics_hub_service_descriptor_config.php b/BigQueryDataExchange/src/V1beta1/resources/analytics_hub_service_descriptor_config.php index bbf1c282901d..483a7d7da69f 100644 --- a/BigQueryDataExchange/src/V1beta1/resources/analytics_hub_service_descriptor_config.php +++ b/BigQueryDataExchange/src/V1beta1/resources/analytics_hub_service_descriptor_config.php @@ -3,6 +3,90 @@ return [ 'interfaces' => [ 'google.cloud.bigquery.dataexchange.v1beta1.AnalyticsHubService' => [ + 'CreateDataExchange' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\BigQuery\DataExchange\V1beta1\DataExchange', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'CreateListing' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\BigQuery\DataExchange\V1beta1\Listing', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'DeleteDataExchange' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Protobuf\GPBEmpty', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'DeleteListing' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Protobuf\GPBEmpty', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetDataExchange' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\BigQuery\DataExchange\V1beta1\DataExchange', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetIamPolicy' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\Policy', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], + ], + 'GetListing' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\BigQuery\DataExchange\V1beta1\Listing', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], 'ListDataExchanges' => [ 'pageStreaming' => [ 'requestPageTokenGetMethod' => 'getPageToken', @@ -12,6 +96,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getDataExchanges', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\BigQuery\DataExchange\V1beta1\ListDataExchangesResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ListListings' => [ 'pageStreaming' => [ @@ -22,6 +116,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getListings', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\BigQuery\DataExchange\V1beta1\ListListingsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ListOrgDataExchanges' => [ 'pageStreaming' => [ @@ -32,8 +136,90 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getDataExchanges', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\BigQuery\DataExchange\V1beta1\ListOrgDataExchangesResponse', + 'headerParams' => [ + [ + 'keyName' => 'organization', + 'fieldAccessors' => [ + 'getOrganization', + ], + ], + ], + ], + 'SetIamPolicy' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\Policy', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], + ], + 'SubscribeListing' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\BigQuery\DataExchange\V1beta1\SubscribeListingResponse', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'TestIamPermissions' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\TestIamPermissionsResponse', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], + ], + 'UpdateDataExchange' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\BigQuery\DataExchange\V1beta1\DataExchange', + 'headerParams' => [ + [ + 'keyName' => 'data_exchange.name', + 'fieldAccessors' => [ + 'getDataExchange', + 'getName', + ], + ], + ], + ], + 'UpdateListing' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\BigQuery\DataExchange\V1beta1\Listing', + 'headerParams' => [ + [ + 'keyName' => 'listing.name', + 'fieldAccessors' => [ + 'getListing', + 'getName', + ], + ], + ], ], 'GetLocation' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Location\Location', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], 'interfaceOverride' => 'google.cloud.location.Locations', ], 'ListLocations' => [ @@ -45,8 +231,24 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getLocations', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\Location\ListLocationsResponse', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], 'interfaceOverride' => 'google.cloud.location.Locations', ], + 'templateMap' => [ + 'dataExchange' => 'projects/{project}/locations/{location}/dataExchanges/{data_exchange}', + 'dataset' => 'projects/{project}/datasets/{dataset}', + 'listing' => 'projects/{project}/locations/{location}/dataExchanges/{data_exchange}/listings/{listing}', + 'location' => 'projects/{project}/locations/{location}', + ], ], ], ]; diff --git a/BigQueryDataExchange/tests/Unit/V1beta1/Client/AnalyticsHubServiceClientTest.php b/BigQueryDataExchange/tests/Unit/V1beta1/Client/AnalyticsHubServiceClientTest.php new file mode 100644 index 000000000000..b6666bf35f72 --- /dev/null +++ b/BigQueryDataExchange/tests/Unit/V1beta1/Client/AnalyticsHubServiceClientTest.php @@ -0,0 +1,1387 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return AnalyticsHubServiceClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new AnalyticsHubServiceClient($options); + } + + /** @test */ + public function createDataExchangeTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $displayName = 'displayName1615086568'; + $description = 'description-1724546052'; + $primaryContact = 'primaryContact203339491'; + $documentation = 'documentation1587405498'; + $listingCount = 1101038700; + $icon = '121'; + $expectedResponse = new DataExchange(); + $expectedResponse->setName($name); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setDescription($description); + $expectedResponse->setPrimaryContact($primaryContact); + $expectedResponse->setDocumentation($documentation); + $expectedResponse->setListingCount($listingCount); + $expectedResponse->setIcon($icon); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $dataExchangeId = 'dataExchangeId1402219426'; + $dataExchange = new DataExchange(); + $dataExchangeDisplayName = 'dataExchangeDisplayName-1195270080'; + $dataExchange->setDisplayName($dataExchangeDisplayName); + $request = (new CreateDataExchangeRequest()) + ->setParent($formattedParent) + ->setDataExchangeId($dataExchangeId) + ->setDataExchange($dataExchange); + $response = $gapicClient->createDataExchange($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.bigquery.dataexchange.v1beta1.AnalyticsHubService/CreateDataExchange', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getDataExchangeId(); + $this->assertProtobufEquals($dataExchangeId, $actualValue); + $actualValue = $actualRequestObject->getDataExchange(); + $this->assertProtobufEquals($dataExchange, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createDataExchangeExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $dataExchangeId = 'dataExchangeId1402219426'; + $dataExchange = new DataExchange(); + $dataExchangeDisplayName = 'dataExchangeDisplayName-1195270080'; + $dataExchange->setDisplayName($dataExchangeDisplayName); + $request = (new CreateDataExchangeRequest()) + ->setParent($formattedParent) + ->setDataExchangeId($dataExchangeId) + ->setDataExchange($dataExchange); + try { + $gapicClient->createDataExchange($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createListingTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $displayName = 'displayName1615086568'; + $description = 'description-1724546052'; + $primaryContact = 'primaryContact203339491'; + $documentation = 'documentation1587405498'; + $icon = '121'; + $requestAccess = 'requestAccess2059178260'; + $expectedResponse = new Listing(); + $expectedResponse->setName($name); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setDescription($description); + $expectedResponse->setPrimaryContact($primaryContact); + $expectedResponse->setDocumentation($documentation); + $expectedResponse->setIcon($icon); + $expectedResponse->setRequestAccess($requestAccess); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->dataExchangeName('[PROJECT]', '[LOCATION]', '[DATA_EXCHANGE]'); + $listingId = 'listingId988969142'; + $listing = new Listing(); + $listingDisplayName = 'listingDisplayName293456201'; + $listing->setDisplayName($listingDisplayName); + $listingBigqueryDataset = new BigQueryDatasetSource(); + $listing->setBigqueryDataset($listingBigqueryDataset); + $request = (new CreateListingRequest()) + ->setParent($formattedParent) + ->setListingId($listingId) + ->setListing($listing); + $response = $gapicClient->createListing($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.bigquery.dataexchange.v1beta1.AnalyticsHubService/CreateListing', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getListingId(); + $this->assertProtobufEquals($listingId, $actualValue); + $actualValue = $actualRequestObject->getListing(); + $this->assertProtobufEquals($listing, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createListingExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->dataExchangeName('[PROJECT]', '[LOCATION]', '[DATA_EXCHANGE]'); + $listingId = 'listingId988969142'; + $listing = new Listing(); + $listingDisplayName = 'listingDisplayName293456201'; + $listing->setDisplayName($listingDisplayName); + $listingBigqueryDataset = new BigQueryDatasetSource(); + $listing->setBigqueryDataset($listingBigqueryDataset); + $request = (new CreateListingRequest()) + ->setParent($formattedParent) + ->setListingId($listingId) + ->setListing($listing); + try { + $gapicClient->createListing($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteDataExchangeTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new GPBEmpty(); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->dataExchangeName('[PROJECT]', '[LOCATION]', '[DATA_EXCHANGE]'); + $request = (new DeleteDataExchangeRequest()) + ->setName($formattedName); + $gapicClient->deleteDataExchange($request); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.bigquery.dataexchange.v1beta1.AnalyticsHubService/DeleteDataExchange', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteDataExchangeExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->dataExchangeName('[PROJECT]', '[LOCATION]', '[DATA_EXCHANGE]'); + $request = (new DeleteDataExchangeRequest()) + ->setName($formattedName); + try { + $gapicClient->deleteDataExchange($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteListingTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new GPBEmpty(); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->listingName('[PROJECT]', '[LOCATION]', '[DATA_EXCHANGE]', '[LISTING]'); + $request = (new DeleteListingRequest()) + ->setName($formattedName); + $gapicClient->deleteListing($request); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.bigquery.dataexchange.v1beta1.AnalyticsHubService/DeleteListing', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteListingExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->listingName('[PROJECT]', '[LOCATION]', '[DATA_EXCHANGE]', '[LISTING]'); + $request = (new DeleteListingRequest()) + ->setName($formattedName); + try { + $gapicClient->deleteListing($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getDataExchangeTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $displayName = 'displayName1615086568'; + $description = 'description-1724546052'; + $primaryContact = 'primaryContact203339491'; + $documentation = 'documentation1587405498'; + $listingCount = 1101038700; + $icon = '121'; + $expectedResponse = new DataExchange(); + $expectedResponse->setName($name2); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setDescription($description); + $expectedResponse->setPrimaryContact($primaryContact); + $expectedResponse->setDocumentation($documentation); + $expectedResponse->setListingCount($listingCount); + $expectedResponse->setIcon($icon); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->dataExchangeName('[PROJECT]', '[LOCATION]', '[DATA_EXCHANGE]'); + $request = (new GetDataExchangeRequest()) + ->setName($formattedName); + $response = $gapicClient->getDataExchange($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.bigquery.dataexchange.v1beta1.AnalyticsHubService/GetDataExchange', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getDataExchangeExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->dataExchangeName('[PROJECT]', '[LOCATION]', '[DATA_EXCHANGE]'); + $request = (new GetDataExchangeRequest()) + ->setName($formattedName); + try { + $gapicClient->getDataExchange($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getIamPolicyTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $version = 351608024; + $etag = '21'; + $expectedResponse = new Policy(); + $expectedResponse->setVersion($version); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + $response = $gapicClient->getIamPolicy($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.bigquery.dataexchange.v1beta1.AnalyticsHubService/GetIamPolicy', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getIamPolicyExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $resource = 'resource-341064690'; + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + try { + $gapicClient->getIamPolicy($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getListingTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $displayName = 'displayName1615086568'; + $description = 'description-1724546052'; + $primaryContact = 'primaryContact203339491'; + $documentation = 'documentation1587405498'; + $icon = '121'; + $requestAccess = 'requestAccess2059178260'; + $expectedResponse = new Listing(); + $expectedResponse->setName($name2); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setDescription($description); + $expectedResponse->setPrimaryContact($primaryContact); + $expectedResponse->setDocumentation($documentation); + $expectedResponse->setIcon($icon); + $expectedResponse->setRequestAccess($requestAccess); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->listingName('[PROJECT]', '[LOCATION]', '[DATA_EXCHANGE]', '[LISTING]'); + $request = (new GetListingRequest()) + ->setName($formattedName); + $response = $gapicClient->getListing($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.bigquery.dataexchange.v1beta1.AnalyticsHubService/GetListing', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getListingExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->listingName('[PROJECT]', '[LOCATION]', '[DATA_EXCHANGE]', '[LISTING]'); + $request = (new GetListingRequest()) + ->setName($formattedName); + try { + $gapicClient->getListing($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listDataExchangesTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $dataExchangesElement = new DataExchange(); + $dataExchanges = [ + $dataExchangesElement, + ]; + $expectedResponse = new ListDataExchangesResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setDataExchanges($dataExchanges); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListDataExchangesRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listDataExchanges($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getDataExchanges()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.bigquery.dataexchange.v1beta1.AnalyticsHubService/ListDataExchanges', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listDataExchangesExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListDataExchangesRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listDataExchanges($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listListingsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $listingsElement = new Listing(); + $listings = [ + $listingsElement, + ]; + $expectedResponse = new ListListingsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setListings($listings); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->dataExchangeName('[PROJECT]', '[LOCATION]', '[DATA_EXCHANGE]'); + $request = (new ListListingsRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listListings($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getListings()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.bigquery.dataexchange.v1beta1.AnalyticsHubService/ListListings', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listListingsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->dataExchangeName('[PROJECT]', '[LOCATION]', '[DATA_EXCHANGE]'); + $request = (new ListListingsRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listListings($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listOrgDataExchangesTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $dataExchangesElement = new DataExchange(); + $dataExchanges = [ + $dataExchangesElement, + ]; + $expectedResponse = new ListOrgDataExchangesResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setDataExchanges($dataExchanges); + $transport->addResponse($expectedResponse); + // Mock request + $organization = 'organization1178922291'; + $request = (new ListOrgDataExchangesRequest()) + ->setOrganization($organization); + $response = $gapicClient->listOrgDataExchanges($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getDataExchanges()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.bigquery.dataexchange.v1beta1.AnalyticsHubService/ListOrgDataExchanges', $actualFuncCall); + $actualValue = $actualRequestObject->getOrganization(); + $this->assertProtobufEquals($organization, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listOrgDataExchangesExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $organization = 'organization1178922291'; + $request = (new ListOrgDataExchangesRequest()) + ->setOrganization($organization); + try { + $gapicClient->listOrgDataExchanges($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function setIamPolicyTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $version = 351608024; + $etag = '21'; + $expectedResponse = new Policy(); + $expectedResponse->setVersion($version); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $policy = new Policy(); + $request = (new SetIamPolicyRequest()) + ->setResource($resource) + ->setPolicy($policy); + $response = $gapicClient->setIamPolicy($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.bigquery.dataexchange.v1beta1.AnalyticsHubService/SetIamPolicy', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $actualValue = $actualRequestObject->getPolicy(); + $this->assertProtobufEquals($policy, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function setIamPolicyExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $resource = 'resource-341064690'; + $policy = new Policy(); + $request = (new SetIamPolicyRequest()) + ->setResource($resource) + ->setPolicy($policy); + try { + $gapicClient->setIamPolicy($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function subscribeListingTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new SubscribeListingResponse(); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->listingName('[PROJECT]', '[LOCATION]', '[DATA_EXCHANGE]', '[LISTING]'); + $request = (new SubscribeListingRequest()) + ->setName($formattedName); + $response = $gapicClient->subscribeListing($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.bigquery.dataexchange.v1beta1.AnalyticsHubService/SubscribeListing', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function subscribeListingExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->listingName('[PROJECT]', '[LOCATION]', '[DATA_EXCHANGE]', '[LISTING]'); + $request = (new SubscribeListingRequest()) + ->setName($formattedName); + try { + $gapicClient->subscribeListing($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function testIamPermissionsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new TestIamPermissionsResponse(); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $permissions = []; + $request = (new TestIamPermissionsRequest()) + ->setResource($resource) + ->setPermissions($permissions); + $response = $gapicClient->testIamPermissions($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.bigquery.dataexchange.v1beta1.AnalyticsHubService/TestIamPermissions', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $actualValue = $actualRequestObject->getPermissions(); + $this->assertProtobufEquals($permissions, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function testIamPermissionsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $resource = 'resource-341064690'; + $permissions = []; + $request = (new TestIamPermissionsRequest()) + ->setResource($resource) + ->setPermissions($permissions); + try { + $gapicClient->testIamPermissions($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function updateDataExchangeTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $displayName = 'displayName1615086568'; + $description = 'description-1724546052'; + $primaryContact = 'primaryContact203339491'; + $documentation = 'documentation1587405498'; + $listingCount = 1101038700; + $icon = '121'; + $expectedResponse = new DataExchange(); + $expectedResponse->setName($name); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setDescription($description); + $expectedResponse->setPrimaryContact($primaryContact); + $expectedResponse->setDocumentation($documentation); + $expectedResponse->setListingCount($listingCount); + $expectedResponse->setIcon($icon); + $transport->addResponse($expectedResponse); + // Mock request + $updateMask = new FieldMask(); + $dataExchange = new DataExchange(); + $dataExchangeDisplayName = 'dataExchangeDisplayName-1195270080'; + $dataExchange->setDisplayName($dataExchangeDisplayName); + $request = (new UpdateDataExchangeRequest()) + ->setUpdateMask($updateMask) + ->setDataExchange($dataExchange); + $response = $gapicClient->updateDataExchange($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.bigquery.dataexchange.v1beta1.AnalyticsHubService/UpdateDataExchange', $actualFuncCall); + $actualValue = $actualRequestObject->getUpdateMask(); + $this->assertProtobufEquals($updateMask, $actualValue); + $actualValue = $actualRequestObject->getDataExchange(); + $this->assertProtobufEquals($dataExchange, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function updateDataExchangeExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $updateMask = new FieldMask(); + $dataExchange = new DataExchange(); + $dataExchangeDisplayName = 'dataExchangeDisplayName-1195270080'; + $dataExchange->setDisplayName($dataExchangeDisplayName); + $request = (new UpdateDataExchangeRequest()) + ->setUpdateMask($updateMask) + ->setDataExchange($dataExchange); + try { + $gapicClient->updateDataExchange($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function updateListingTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $displayName = 'displayName1615086568'; + $description = 'description-1724546052'; + $primaryContact = 'primaryContact203339491'; + $documentation = 'documentation1587405498'; + $icon = '121'; + $requestAccess = 'requestAccess2059178260'; + $expectedResponse = new Listing(); + $expectedResponse->setName($name); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setDescription($description); + $expectedResponse->setPrimaryContact($primaryContact); + $expectedResponse->setDocumentation($documentation); + $expectedResponse->setIcon($icon); + $expectedResponse->setRequestAccess($requestAccess); + $transport->addResponse($expectedResponse); + // Mock request + $updateMask = new FieldMask(); + $listing = new Listing(); + $listingDisplayName = 'listingDisplayName293456201'; + $listing->setDisplayName($listingDisplayName); + $listingBigqueryDataset = new BigQueryDatasetSource(); + $listing->setBigqueryDataset($listingBigqueryDataset); + $request = (new UpdateListingRequest()) + ->setUpdateMask($updateMask) + ->setListing($listing); + $response = $gapicClient->updateListing($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.bigquery.dataexchange.v1beta1.AnalyticsHubService/UpdateListing', $actualFuncCall); + $actualValue = $actualRequestObject->getUpdateMask(); + $this->assertProtobufEquals($updateMask, $actualValue); + $actualValue = $actualRequestObject->getListing(); + $this->assertProtobufEquals($listing, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function updateListingExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $updateMask = new FieldMask(); + $listing = new Listing(); + $listingDisplayName = 'listingDisplayName293456201'; + $listing->setDisplayName($listingDisplayName); + $listingBigqueryDataset = new BigQueryDatasetSource(); + $listing->setBigqueryDataset($listingBigqueryDataset); + $request = (new UpdateListingRequest()) + ->setUpdateMask($updateMask) + ->setListing($listing); + try { + $gapicClient->updateListing($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getLocationTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $locationId = 'locationId552319461'; + $displayName = 'displayName1615086568'; + $expectedResponse = new Location(); + $expectedResponse->setName($name2); + $expectedResponse->setLocationId($locationId); + $expectedResponse->setDisplayName($displayName); + $transport->addResponse($expectedResponse); + $request = new GetLocationRequest(); + $response = $gapicClient->getLocation($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.location.Locations/GetLocation', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getLocationExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + $request = new GetLocationRequest(); + try { + $gapicClient->getLocation($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listLocationsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $locationsElement = new Location(); + $locations = [ + $locationsElement, + ]; + $expectedResponse = new ListLocationsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setLocations($locations); + $transport->addResponse($expectedResponse); + $request = new ListLocationsRequest(); + $response = $gapicClient->listLocations($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getLocations()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.location.Locations/ListLocations', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listLocationsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + $request = new ListLocationsRequest(); + try { + $gapicClient->listLocations($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createDataExchangeAsyncTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $displayName = 'displayName1615086568'; + $description = 'description-1724546052'; + $primaryContact = 'primaryContact203339491'; + $documentation = 'documentation1587405498'; + $listingCount = 1101038700; + $icon = '121'; + $expectedResponse = new DataExchange(); + $expectedResponse->setName($name); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setDescription($description); + $expectedResponse->setPrimaryContact($primaryContact); + $expectedResponse->setDocumentation($documentation); + $expectedResponse->setListingCount($listingCount); + $expectedResponse->setIcon($icon); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $dataExchangeId = 'dataExchangeId1402219426'; + $dataExchange = new DataExchange(); + $dataExchangeDisplayName = 'dataExchangeDisplayName-1195270080'; + $dataExchange->setDisplayName($dataExchangeDisplayName); + $request = (new CreateDataExchangeRequest()) + ->setParent($formattedParent) + ->setDataExchangeId($dataExchangeId) + ->setDataExchange($dataExchange); + $response = $gapicClient->createDataExchangeAsync($request)->wait(); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.bigquery.dataexchange.v1beta1.AnalyticsHubService/CreateDataExchange', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getDataExchangeId(); + $this->assertProtobufEquals($dataExchangeId, $actualValue); + $actualValue = $actualRequestObject->getDataExchange(); + $this->assertProtobufEquals($dataExchange, $actualValue); + $this->assertTrue($transport->isExhausted()); + } +} diff --git a/BigQueryDataPolicies/samples/V1/DataPolicyServiceClient/create_data_policy.php b/BigQueryDataPolicies/samples/V1/DataPolicyServiceClient/create_data_policy.php index aba7061014b4..1644a2e5f03a 100644 --- a/BigQueryDataPolicies/samples/V1/DataPolicyServiceClient/create_data_policy.php +++ b/BigQueryDataPolicies/samples/V1/DataPolicyServiceClient/create_data_policy.php @@ -24,8 +24,9 @@ // [START bigquerydatapolicy_v1_generated_DataPolicyService_CreateDataPolicy_sync] use Google\ApiCore\ApiException; +use Google\Cloud\BigQuery\DataPolicies\V1\Client\DataPolicyServiceClient; +use Google\Cloud\BigQuery\DataPolicies\V1\CreateDataPolicyRequest; use Google\Cloud\BigQuery\DataPolicies\V1\DataPolicy; -use Google\Cloud\BigQuery\DataPolicies\V1\DataPolicyServiceClient; /** * Creates a new data policy under a project with the given `dataPolicyId` @@ -40,13 +41,16 @@ function create_data_policy_sample(string $formattedParent): void // Create a client. $dataPolicyServiceClient = new DataPolicyServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $dataPolicy = new DataPolicy(); + $request = (new CreateDataPolicyRequest()) + ->setParent($formattedParent) + ->setDataPolicy($dataPolicy); // Call the API and handle any network failures. try { /** @var DataPolicy $response */ - $response = $dataPolicyServiceClient->createDataPolicy($formattedParent, $dataPolicy); + $response = $dataPolicyServiceClient->createDataPolicy($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BigQueryDataPolicies/samples/V1/DataPolicyServiceClient/delete_data_policy.php b/BigQueryDataPolicies/samples/V1/DataPolicyServiceClient/delete_data_policy.php index d80ccbda5608..1ff7c2b2f8dc 100644 --- a/BigQueryDataPolicies/samples/V1/DataPolicyServiceClient/delete_data_policy.php +++ b/BigQueryDataPolicies/samples/V1/DataPolicyServiceClient/delete_data_policy.php @@ -24,7 +24,8 @@ // [START bigquerydatapolicy_v1_generated_DataPolicyService_DeleteDataPolicy_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BigQuery\DataPolicies\V1\DataPolicyServiceClient; +use Google\Cloud\BigQuery\DataPolicies\V1\Client\DataPolicyServiceClient; +use Google\Cloud\BigQuery\DataPolicies\V1\DeleteDataPolicyRequest; /** * Deletes the data policy specified by its resource name. @@ -38,9 +39,13 @@ function delete_data_policy_sample(string $formattedName): void // Create a client. $dataPolicyServiceClient = new DataPolicyServiceClient(); + // Prepare the request message. + $request = (new DeleteDataPolicyRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { - $dataPolicyServiceClient->deleteDataPolicy($formattedName); + $dataPolicyServiceClient->deleteDataPolicy($request); printf('Call completed successfully.' . PHP_EOL); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BigQueryDataPolicies/samples/V1/DataPolicyServiceClient/get_data_policy.php b/BigQueryDataPolicies/samples/V1/DataPolicyServiceClient/get_data_policy.php index b5384d195f23..57e367b6c8b0 100644 --- a/BigQueryDataPolicies/samples/V1/DataPolicyServiceClient/get_data_policy.php +++ b/BigQueryDataPolicies/samples/V1/DataPolicyServiceClient/get_data_policy.php @@ -24,8 +24,9 @@ // [START bigquerydatapolicy_v1_generated_DataPolicyService_GetDataPolicy_sync] use Google\ApiCore\ApiException; +use Google\Cloud\BigQuery\DataPolicies\V1\Client\DataPolicyServiceClient; use Google\Cloud\BigQuery\DataPolicies\V1\DataPolicy; -use Google\Cloud\BigQuery\DataPolicies\V1\DataPolicyServiceClient; +use Google\Cloud\BigQuery\DataPolicies\V1\GetDataPolicyRequest; /** * Gets the data policy specified by its resource name. @@ -39,10 +40,14 @@ function get_data_policy_sample(string $formattedName): void // Create a client. $dataPolicyServiceClient = new DataPolicyServiceClient(); + // Prepare the request message. + $request = (new GetDataPolicyRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var DataPolicy $response */ - $response = $dataPolicyServiceClient->getDataPolicy($formattedName); + $response = $dataPolicyServiceClient->getDataPolicy($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BigQueryDataPolicies/samples/V1/DataPolicyServiceClient/get_iam_policy.php b/BigQueryDataPolicies/samples/V1/DataPolicyServiceClient/get_iam_policy.php index 602f4ee4495f..d1dbe6d77bf9 100644 --- a/BigQueryDataPolicies/samples/V1/DataPolicyServiceClient/get_iam_policy.php +++ b/BigQueryDataPolicies/samples/V1/DataPolicyServiceClient/get_iam_policy.php @@ -24,7 +24,8 @@ // [START bigquerydatapolicy_v1_generated_DataPolicyService_GetIamPolicy_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BigQuery\DataPolicies\V1\DataPolicyServiceClient; +use Google\Cloud\BigQuery\DataPolicies\V1\Client\DataPolicyServiceClient; +use Google\Cloud\Iam\V1\GetIamPolicyRequest; use Google\Cloud\Iam\V1\Policy; /** @@ -38,10 +39,14 @@ function get_iam_policy_sample(string $resource): void // Create a client. $dataPolicyServiceClient = new DataPolicyServiceClient(); + // Prepare the request message. + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + // Call the API and handle any network failures. try { /** @var Policy $response */ - $response = $dataPolicyServiceClient->getIamPolicy($resource); + $response = $dataPolicyServiceClient->getIamPolicy($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BigQueryDataPolicies/samples/V1/DataPolicyServiceClient/list_data_policies.php b/BigQueryDataPolicies/samples/V1/DataPolicyServiceClient/list_data_policies.php index 111cdcecbbae..1aa07e6dd506 100644 --- a/BigQueryDataPolicies/samples/V1/DataPolicyServiceClient/list_data_policies.php +++ b/BigQueryDataPolicies/samples/V1/DataPolicyServiceClient/list_data_policies.php @@ -25,8 +25,9 @@ // [START bigquerydatapolicy_v1_generated_DataPolicyService_ListDataPolicies_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; +use Google\Cloud\BigQuery\DataPolicies\V1\Client\DataPolicyServiceClient; use Google\Cloud\BigQuery\DataPolicies\V1\DataPolicy; -use Google\Cloud\BigQuery\DataPolicies\V1\DataPolicyServiceClient; +use Google\Cloud\BigQuery\DataPolicies\V1\ListDataPoliciesRequest; /** * List all of the data policies in the specified parent project. @@ -40,10 +41,14 @@ function list_data_policies_sample(string $formattedParent): void // Create a client. $dataPolicyServiceClient = new DataPolicyServiceClient(); + // Prepare the request message. + $request = (new ListDataPoliciesRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $dataPolicyServiceClient->listDataPolicies($formattedParent); + $response = $dataPolicyServiceClient->listDataPolicies($request); /** @var DataPolicy $element */ foreach ($response as $element) { diff --git a/BigQueryDataPolicies/samples/V1/DataPolicyServiceClient/rename_data_policy.php b/BigQueryDataPolicies/samples/V1/DataPolicyServiceClient/rename_data_policy.php index e8d3f96c7ca7..347f80076fff 100644 --- a/BigQueryDataPolicies/samples/V1/DataPolicyServiceClient/rename_data_policy.php +++ b/BigQueryDataPolicies/samples/V1/DataPolicyServiceClient/rename_data_policy.php @@ -24,8 +24,9 @@ // [START bigquerydatapolicy_v1_generated_DataPolicyService_RenameDataPolicy_sync] use Google\ApiCore\ApiException; +use Google\Cloud\BigQuery\DataPolicies\V1\Client\DataPolicyServiceClient; use Google\Cloud\BigQuery\DataPolicies\V1\DataPolicy; -use Google\Cloud\BigQuery\DataPolicies\V1\DataPolicyServiceClient; +use Google\Cloud\BigQuery\DataPolicies\V1\RenameDataPolicyRequest; /** * Renames the id (display name) of the specified data policy. @@ -39,10 +40,15 @@ function rename_data_policy_sample(string $name, string $newDataPolicyId): void // Create a client. $dataPolicyServiceClient = new DataPolicyServiceClient(); + // Prepare the request message. + $request = (new RenameDataPolicyRequest()) + ->setName($name) + ->setNewDataPolicyId($newDataPolicyId); + // Call the API and handle any network failures. try { /** @var DataPolicy $response */ - $response = $dataPolicyServiceClient->renameDataPolicy($name, $newDataPolicyId); + $response = $dataPolicyServiceClient->renameDataPolicy($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BigQueryDataPolicies/samples/V1/DataPolicyServiceClient/set_iam_policy.php b/BigQueryDataPolicies/samples/V1/DataPolicyServiceClient/set_iam_policy.php index 6c42621189ed..a085230bebf7 100644 --- a/BigQueryDataPolicies/samples/V1/DataPolicyServiceClient/set_iam_policy.php +++ b/BigQueryDataPolicies/samples/V1/DataPolicyServiceClient/set_iam_policy.php @@ -24,8 +24,9 @@ // [START bigquerydatapolicy_v1_generated_DataPolicyService_SetIamPolicy_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BigQuery\DataPolicies\V1\DataPolicyServiceClient; +use Google\Cloud\BigQuery\DataPolicies\V1\Client\DataPolicyServiceClient; use Google\Cloud\Iam\V1\Policy; +use Google\Cloud\Iam\V1\SetIamPolicyRequest; /** * Sets the IAM policy for the specified data policy. @@ -38,13 +39,16 @@ function set_iam_policy_sample(string $resource): void // Create a client. $dataPolicyServiceClient = new DataPolicyServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $policy = new Policy(); + $request = (new SetIamPolicyRequest()) + ->setResource($resource) + ->setPolicy($policy); // Call the API and handle any network failures. try { /** @var Policy $response */ - $response = $dataPolicyServiceClient->setIamPolicy($resource, $policy); + $response = $dataPolicyServiceClient->setIamPolicy($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BigQueryDataPolicies/samples/V1/DataPolicyServiceClient/test_iam_permissions.php b/BigQueryDataPolicies/samples/V1/DataPolicyServiceClient/test_iam_permissions.php index 99e6d19e3da5..14dafcc60d24 100644 --- a/BigQueryDataPolicies/samples/V1/DataPolicyServiceClient/test_iam_permissions.php +++ b/BigQueryDataPolicies/samples/V1/DataPolicyServiceClient/test_iam_permissions.php @@ -24,7 +24,8 @@ // [START bigquerydatapolicy_v1_generated_DataPolicyService_TestIamPermissions_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BigQuery\DataPolicies\V1\DataPolicyServiceClient; +use Google\Cloud\BigQuery\DataPolicies\V1\Client\DataPolicyServiceClient; +use Google\Cloud\Iam\V1\TestIamPermissionsRequest; use Google\Cloud\Iam\V1\TestIamPermissionsResponse; /** @@ -42,13 +43,16 @@ function test_iam_permissions_sample(string $resource, string $permissionsElemen // Create a client. $dataPolicyServiceClient = new DataPolicyServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $permissions = [$permissionsElement,]; + $request = (new TestIamPermissionsRequest()) + ->setResource($resource) + ->setPermissions($permissions); // Call the API and handle any network failures. try { /** @var TestIamPermissionsResponse $response */ - $response = $dataPolicyServiceClient->testIamPermissions($resource, $permissions); + $response = $dataPolicyServiceClient->testIamPermissions($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BigQueryDataPolicies/samples/V1/DataPolicyServiceClient/update_data_policy.php b/BigQueryDataPolicies/samples/V1/DataPolicyServiceClient/update_data_policy.php index f5ac566bcb0e..a23c5c164e83 100644 --- a/BigQueryDataPolicies/samples/V1/DataPolicyServiceClient/update_data_policy.php +++ b/BigQueryDataPolicies/samples/V1/DataPolicyServiceClient/update_data_policy.php @@ -24,8 +24,9 @@ // [START bigquerydatapolicy_v1_generated_DataPolicyService_UpdateDataPolicy_sync] use Google\ApiCore\ApiException; +use Google\Cloud\BigQuery\DataPolicies\V1\Client\DataPolicyServiceClient; use Google\Cloud\BigQuery\DataPolicies\V1\DataPolicy; -use Google\Cloud\BigQuery\DataPolicies\V1\DataPolicyServiceClient; +use Google\Cloud\BigQuery\DataPolicies\V1\UpdateDataPolicyRequest; /** * Updates the metadata for an existing data policy. The target data policy @@ -42,13 +43,15 @@ function update_data_policy_sample(): void // Create a client. $dataPolicyServiceClient = new DataPolicyServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $dataPolicy = new DataPolicy(); + $request = (new UpdateDataPolicyRequest()) + ->setDataPolicy($dataPolicy); // Call the API and handle any network failures. try { /** @var DataPolicy $response */ - $response = $dataPolicyServiceClient->updateDataPolicy($dataPolicy); + $response = $dataPolicyServiceClient->updateDataPolicy($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BigQueryDataPolicies/src/V1/Client/BaseClient/DataPolicyServiceBaseClient.php b/BigQueryDataPolicies/src/V1/Client/BaseClient/DataPolicyServiceBaseClient.php new file mode 100644 index 000000000000..440af69d1922 --- /dev/null +++ b/BigQueryDataPolicies/src/V1/Client/BaseClient/DataPolicyServiceBaseClient.php @@ -0,0 +1,466 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/data_policy_service_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/data_policy_service_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/data_policy_service_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/data_policy_service_rest_client_config.php', + ], + ], + ]; + } + + /** + * Formats a string containing the fully-qualified path to represent a data_policy + * resource. + * + * @param string $project + * @param string $location + * @param string $dataPolicy + * + * @return string The formatted data_policy resource. + */ + public static function dataPolicyName(string $project, string $location, string $dataPolicy): string + { + return self::getPathTemplate('dataPolicy')->render([ + 'project' => $project, + 'location' => $location, + 'data_policy' => $dataPolicy, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a location + * resource. + * + * @param string $project + * @param string $location + * + * @return string The formatted location resource. + */ + public static function locationName(string $project, string $location): string + { + return self::getPathTemplate('location')->render([ + 'project' => $project, + 'location' => $location, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * Template: Pattern + * - dataPolicy: projects/{project}/locations/{location}/dataPolicies/{data_policy} + * - location: projects/{project}/locations/{location} + * + * The optional $template argument can be supplied to specify a particular pattern, + * and must match one of the templates listed above. If no $template argument is + * provided, or if the $template argument does not match one of the templates + * listed, then parseName will check each of the supported templates, and return + * the first match. + * + * @param string $formattedName The formatted name string + * @param string $template Optional name of template to match + * + * @return array An associative array from name component IDs to component values. + * + * @throws ValidationException If $formattedName could not be matched. + */ + public static function parseName(string $formattedName, string $template = null): array + { + return self::parseFormattedName($formattedName, $template); + } + + /** + * Constructor. + * + * @param array $options { + * Optional. Options for configuring the service API wrapper. + * + * @type string $apiEndpoint + * The address of the API remote host. May optionally include the port, formatted + * as ":". Default 'bigquerydatapolicy.googleapis.com:443'. + * @type string|array|FetchAuthTokenInterface|CredentialsWrapper $credentials + * The credentials to be used by the client to authorize API calls. This option + * accepts either a path to a credentials file, or a decoded credentials file as a + * PHP array. + * *Advanced usage*: In addition, this option can also accept a pre-constructed + * {@see \Google\Auth\FetchAuthTokenInterface} object or + * {@see \Google\ApiCore\CredentialsWrapper} object. Note that when one of these + * objects are provided, any settings in $credentialsConfig will be ignored. + * @type array $credentialsConfig + * Options used to configure credentials, including auth token caching, for the + * client. For a full list of supporting configuration options, see + * {@see \Google\ApiCore\CredentialsWrapper::build()} . + * @type bool $disableRetries + * Determines whether or not retries defined by the client configuration should be + * disabled. Defaults to `false`. + * @type string|array $clientConfig + * Client method configuration, including retry settings. This option can be either + * a path to a JSON file, or a PHP array containing the decoded JSON data. By + * default this settings points to the default client config file, which is + * provided in the resources folder. + * @type string|TransportInterface $transport + * The transport used for executing network requests. May be either the string + * `rest` or `grpc`. Defaults to `grpc` if gRPC support is detected on the system. + * *Advanced usage*: Additionally, it is possible to pass in an already + * instantiated {@see \Google\ApiCore\Transport\TransportInterface} object. Note + * that when this object is provided, any settings in $transportConfig, and any + * $apiEndpoint setting, will be ignored. + * @type array $transportConfig + * Configuration options that will be used to construct the transport. Options for + * each supported transport type should be passed in a key for that transport. For + * example: + * $transportConfig = [ + * 'grpc' => [...], + * 'rest' => [...], + * ]; + * See the {@see \Google\ApiCore\Transport\GrpcTransport::build()} and + * {@see \Google\ApiCore\Transport\RestTransport::build()} methods for the + * supported options. + * @type callable $clientCertSource + * A callable which returns the client cert as a string. This can be used to + * provide a certificate and private key to the transport layer for mTLS. + * } + * + * @throws ValidationException + */ + public function __construct(array $options = []) + { + $clientOptions = $this->buildClientOptions($options); + $this->setClientOptions($clientOptions); + } + + /** Handles execution of the async variants for each documented method. */ + public function __call($method, $args) + { + if (substr($method, -5) !== 'Async') { + trigger_error('Call to undefined method ' . __CLASS__ . "::$method()", E_USER_ERROR); + } + + array_unshift($args, substr($method, 0, -5)); + return call_user_func_array([$this, 'startAsyncCall'], $args); + } + + /** + * Creates a new data policy under a project with the given `dataPolicyId` + * (used as the display name), policy tag, and data policy type. + * + * The async variant is {@see self::createDataPolicyAsync()} . + * + * @param CreateDataPolicyRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return DataPolicy + * + * @throws ApiException Thrown if the API call fails. + */ + public function createDataPolicy(CreateDataPolicyRequest $request, array $callOptions = []): DataPolicy + { + return $this->startApiCall('CreateDataPolicy', $request, $callOptions)->wait(); + } + + /** + * Deletes the data policy specified by its resource name. + * + * The async variant is {@see self::deleteDataPolicyAsync()} . + * + * @param DeleteDataPolicyRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @throws ApiException Thrown if the API call fails. + */ + public function deleteDataPolicy(DeleteDataPolicyRequest $request, array $callOptions = []): void + { + $this->startApiCall('DeleteDataPolicy', $request, $callOptions)->wait(); + } + + /** + * Gets the data policy specified by its resource name. + * + * The async variant is {@see self::getDataPolicyAsync()} . + * + * @param GetDataPolicyRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return DataPolicy + * + * @throws ApiException Thrown if the API call fails. + */ + public function getDataPolicy(GetDataPolicyRequest $request, array $callOptions = []): DataPolicy + { + return $this->startApiCall('GetDataPolicy', $request, $callOptions)->wait(); + } + + /** + * Gets the IAM policy for the specified data policy. + * + * The async variant is {@see self::getIamPolicyAsync()} . + * + * @param GetIamPolicyRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Policy + * + * @throws ApiException Thrown if the API call fails. + */ + public function getIamPolicy(GetIamPolicyRequest $request, array $callOptions = []): Policy + { + return $this->startApiCall('GetIamPolicy', $request, $callOptions)->wait(); + } + + /** + * List all of the data policies in the specified parent project. + * + * The async variant is {@see self::listDataPoliciesAsync()} . + * + * @param ListDataPoliciesRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listDataPolicies(ListDataPoliciesRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListDataPolicies', $request, $callOptions); + } + + /** + * Renames the id (display name) of the specified data policy. + * + * The async variant is {@see self::renameDataPolicyAsync()} . + * + * @param RenameDataPolicyRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return DataPolicy + * + * @throws ApiException Thrown if the API call fails. + */ + public function renameDataPolicy(RenameDataPolicyRequest $request, array $callOptions = []): DataPolicy + { + return $this->startApiCall('RenameDataPolicy', $request, $callOptions)->wait(); + } + + /** + * Sets the IAM policy for the specified data policy. + * + * The async variant is {@see self::setIamPolicyAsync()} . + * + * @param SetIamPolicyRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Policy + * + * @throws ApiException Thrown if the API call fails. + */ + public function setIamPolicy(SetIamPolicyRequest $request, array $callOptions = []): Policy + { + return $this->startApiCall('SetIamPolicy', $request, $callOptions)->wait(); + } + + /** + * Returns the caller's permission on the specified data policy resource. + * + * The async variant is {@see self::testIamPermissionsAsync()} . + * + * @param TestIamPermissionsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return TestIamPermissionsResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function testIamPermissions(TestIamPermissionsRequest $request, array $callOptions = []): TestIamPermissionsResponse + { + return $this->startApiCall('TestIamPermissions', $request, $callOptions)->wait(); + } + + /** + * Updates the metadata for an existing data policy. The target data policy + * can be specified by the resource name. + * + * The async variant is {@see self::updateDataPolicyAsync()} . + * + * @param UpdateDataPolicyRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return DataPolicy + * + * @throws ApiException Thrown if the API call fails. + */ + public function updateDataPolicy(UpdateDataPolicyRequest $request, array $callOptions = []): DataPolicy + { + return $this->startApiCall('UpdateDataPolicy', $request, $callOptions)->wait(); + } +} diff --git a/BigQueryDataPolicies/src/V1/Client/DataPolicyServiceClient.php b/BigQueryDataPolicies/src/V1/Client/DataPolicyServiceClient.php new file mode 100644 index 000000000000..33623d714fe4 --- /dev/null +++ b/BigQueryDataPolicies/src/V1/Client/DataPolicyServiceClient.php @@ -0,0 +1,40 @@ +setParent($parent) + ->setDataPolicy($dataPolicy); + } + /** * Constructor. * diff --git a/BigQueryDataPolicies/src/V1/DeleteDataPolicyRequest.php b/BigQueryDataPolicies/src/V1/DeleteDataPolicyRequest.php index 37108cd4b082..aa5a975f24b3 100644 --- a/BigQueryDataPolicies/src/V1/DeleteDataPolicyRequest.php +++ b/BigQueryDataPolicies/src/V1/DeleteDataPolicyRequest.php @@ -23,6 +23,21 @@ class DeleteDataPolicyRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. Resource name of the data policy to delete. Format is + * `projects/{project_number}/locations/{location_id}/dataPolicies/{data_policy_id}`. Please see + * {@see DataPolicyServiceClient::dataPolicyName()} for help formatting this field. + * + * @return \Google\Cloud\BigQuery\DataPolicies\V1\DeleteDataPolicyRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/BigQueryDataPolicies/src/V1/GetDataPolicyRequest.php b/BigQueryDataPolicies/src/V1/GetDataPolicyRequest.php index de11e4ada486..129f93edf69c 100644 --- a/BigQueryDataPolicies/src/V1/GetDataPolicyRequest.php +++ b/BigQueryDataPolicies/src/V1/GetDataPolicyRequest.php @@ -23,6 +23,21 @@ class GetDataPolicyRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. Resource name of the requested data policy. Format is + * `projects/{project_number}/locations/{location_id}/dataPolicies/{data_policy_id}`. Please see + * {@see DataPolicyServiceClient::dataPolicyName()} for help formatting this field. + * + * @return \Google\Cloud\BigQuery\DataPolicies\V1\GetDataPolicyRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/BigQueryDataPolicies/src/V1/ListDataPoliciesRequest.php b/BigQueryDataPolicies/src/V1/ListDataPoliciesRequest.php index ec169c1d3918..3e2b77351376 100644 --- a/BigQueryDataPolicies/src/V1/ListDataPoliciesRequest.php +++ b/BigQueryDataPolicies/src/V1/ListDataPoliciesRequest.php @@ -50,6 +50,21 @@ class ListDataPoliciesRequest extends \Google\Protobuf\Internal\Message */ private $filter = ''; + /** + * @param string $parent Required. Resource name of the project for which to list data policies. + * Format is `projects/{project_number}/locations/{location_id}`. Please see + * {@see DataPolicyServiceClient::locationName()} for help formatting this field. + * + * @return \Google\Cloud\BigQuery\DataPolicies\V1\ListDataPoliciesRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/BigQueryDataPolicies/src/V1/RenameDataPolicyRequest.php b/BigQueryDataPolicies/src/V1/RenameDataPolicyRequest.php index b3830f8fa7c2..0a3bf2198768 100644 --- a/BigQueryDataPolicies/src/V1/RenameDataPolicyRequest.php +++ b/BigQueryDataPolicies/src/V1/RenameDataPolicyRequest.php @@ -29,6 +29,22 @@ class RenameDataPolicyRequest extends \Google\Protobuf\Internal\Message */ private $new_data_policy_id = ''; + /** + * @param string $name Required. Resource name of the data policy to rename. The format is + * `projects/{project_number}/locations/{location_id}/dataPolicies/{data_policy_id}` + * @param string $newDataPolicyId Required. The new data policy id. + * + * @return \Google\Cloud\BigQuery\DataPolicies\V1\RenameDataPolicyRequest + * + * @experimental + */ + public static function build(string $name, string $newDataPolicyId): self + { + return (new self()) + ->setName($name) + ->setNewDataPolicyId($newDataPolicyId); + } + /** * Constructor. * diff --git a/BigQueryDataPolicies/src/V1/UpdateDataPolicyRequest.php b/BigQueryDataPolicies/src/V1/UpdateDataPolicyRequest.php index c9126ed81880..69396dcaa781 100644 --- a/BigQueryDataPolicies/src/V1/UpdateDataPolicyRequest.php +++ b/BigQueryDataPolicies/src/V1/UpdateDataPolicyRequest.php @@ -34,6 +34,29 @@ class UpdateDataPolicyRequest extends \Google\Protobuf\Internal\Message */ private $update_mask = null; + /** + * @param \Google\Cloud\BigQuery\DataPolicies\V1\DataPolicy $dataPolicy Required. Update the data policy's metadata. + * + * The target data policy is determined by the `name` field. + * Other fields are updated to the specified values based on the field masks. + * @param \Google\Protobuf\FieldMask $updateMask The update mask applies to the resource. For the `FieldMask` definition, + * see + * https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#fieldmask + * If not set, defaults to all of the fields that are allowed to update. + * + * Updates to the `name` and `dataPolicyId` fields are not allowed. + * + * @return \Google\Cloud\BigQuery\DataPolicies\V1\UpdateDataPolicyRequest + * + * @experimental + */ + public static function build(\Google\Cloud\BigQuery\DataPolicies\V1\DataPolicy $dataPolicy, \Google\Protobuf\FieldMask $updateMask): self + { + return (new self()) + ->setDataPolicy($dataPolicy) + ->setUpdateMask($updateMask); + } + /** * Constructor. * diff --git a/BigQueryDataPolicies/src/V1/resources/data_policy_service_descriptor_config.php b/BigQueryDataPolicies/src/V1/resources/data_policy_service_descriptor_config.php index 6aca9ce454e2..cda5186072b8 100644 --- a/BigQueryDataPolicies/src/V1/resources/data_policy_service_descriptor_config.php +++ b/BigQueryDataPolicies/src/V1/resources/data_policy_service_descriptor_config.php @@ -3,6 +3,54 @@ return [ 'interfaces' => [ 'google.cloud.bigquery.datapolicies.v1.DataPolicyService' => [ + 'CreateDataPolicy' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\BigQuery\DataPolicies\V1\DataPolicy', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'DeleteDataPolicy' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Protobuf\GPBEmpty', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetDataPolicy' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\BigQuery\DataPolicies\V1\DataPolicy', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetIamPolicy' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\Policy', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], + ], 'ListDataPolicies' => [ 'pageStreaming' => [ 'requestPageTokenGetMethod' => 'getPageToken', @@ -12,6 +60,69 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getDataPolicies', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\BigQuery\DataPolicies\V1\ListDataPoliciesResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'RenameDataPolicy' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\BigQuery\DataPolicies\V1\DataPolicy', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'SetIamPolicy' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\Policy', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], + ], + 'TestIamPermissions' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\TestIamPermissionsResponse', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], + ], + 'UpdateDataPolicy' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\BigQuery\DataPolicies\V1\DataPolicy', + 'headerParams' => [ + [ + 'keyName' => 'data_policy.name', + 'fieldAccessors' => [ + 'getDataPolicy', + 'getName', + ], + ], + ], + ], + 'templateMap' => [ + 'dataPolicy' => 'projects/{project}/locations/{location}/dataPolicies/{data_policy}', + 'location' => 'projects/{project}/locations/{location}', ], ], ], diff --git a/BigQueryDataPolicies/tests/Unit/V1/Client/DataPolicyServiceClientTest.php b/BigQueryDataPolicies/tests/Unit/V1/Client/DataPolicyServiceClientTest.php new file mode 100644 index 000000000000..13f60b0d7f88 --- /dev/null +++ b/BigQueryDataPolicies/tests/Unit/V1/Client/DataPolicyServiceClientTest.php @@ -0,0 +1,734 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return DataPolicyServiceClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new DataPolicyServiceClient($options); + } + + /** @test */ + public function createDataPolicyTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $policyTag = 'policyTag1593879309'; + $name = 'name3373707'; + $dataPolicyId = 'dataPolicyId456934643'; + $expectedResponse = new DataPolicy(); + $expectedResponse->setPolicyTag($policyTag); + $expectedResponse->setName($name); + $expectedResponse->setDataPolicyId($dataPolicyId); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $dataPolicy = new DataPolicy(); + $request = (new CreateDataPolicyRequest()) + ->setParent($formattedParent) + ->setDataPolicy($dataPolicy); + $response = $gapicClient->createDataPolicy($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.bigquery.datapolicies.v1.DataPolicyService/CreateDataPolicy', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getDataPolicy(); + $this->assertProtobufEquals($dataPolicy, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createDataPolicyExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $dataPolicy = new DataPolicy(); + $request = (new CreateDataPolicyRequest()) + ->setParent($formattedParent) + ->setDataPolicy($dataPolicy); + try { + $gapicClient->createDataPolicy($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteDataPolicyTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new GPBEmpty(); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->dataPolicyName('[PROJECT]', '[LOCATION]', '[DATA_POLICY]'); + $request = (new DeleteDataPolicyRequest()) + ->setName($formattedName); + $gapicClient->deleteDataPolicy($request); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.bigquery.datapolicies.v1.DataPolicyService/DeleteDataPolicy', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteDataPolicyExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->dataPolicyName('[PROJECT]', '[LOCATION]', '[DATA_POLICY]'); + $request = (new DeleteDataPolicyRequest()) + ->setName($formattedName); + try { + $gapicClient->deleteDataPolicy($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getDataPolicyTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $policyTag = 'policyTag1593879309'; + $name2 = 'name2-1052831874'; + $dataPolicyId = 'dataPolicyId456934643'; + $expectedResponse = new DataPolicy(); + $expectedResponse->setPolicyTag($policyTag); + $expectedResponse->setName($name2); + $expectedResponse->setDataPolicyId($dataPolicyId); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->dataPolicyName('[PROJECT]', '[LOCATION]', '[DATA_POLICY]'); + $request = (new GetDataPolicyRequest()) + ->setName($formattedName); + $response = $gapicClient->getDataPolicy($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.bigquery.datapolicies.v1.DataPolicyService/GetDataPolicy', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getDataPolicyExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->dataPolicyName('[PROJECT]', '[LOCATION]', '[DATA_POLICY]'); + $request = (new GetDataPolicyRequest()) + ->setName($formattedName); + try { + $gapicClient->getDataPolicy($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getIamPolicyTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $version = 351608024; + $etag = '21'; + $expectedResponse = new Policy(); + $expectedResponse->setVersion($version); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + $response = $gapicClient->getIamPolicy($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.bigquery.datapolicies.v1.DataPolicyService/GetIamPolicy', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getIamPolicyExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $resource = 'resource-341064690'; + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + try { + $gapicClient->getIamPolicy($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listDataPoliciesTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $dataPoliciesElement = new DataPolicy(); + $dataPolicies = [ + $dataPoliciesElement, + ]; + $expectedResponse = new ListDataPoliciesResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setDataPolicies($dataPolicies); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListDataPoliciesRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listDataPolicies($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getDataPolicies()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.bigquery.datapolicies.v1.DataPolicyService/ListDataPolicies', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listDataPoliciesExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListDataPoliciesRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listDataPolicies($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function renameDataPolicyTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $policyTag = 'policyTag1593879309'; + $name2 = 'name2-1052831874'; + $dataPolicyId = 'dataPolicyId456934643'; + $expectedResponse = new DataPolicy(); + $expectedResponse->setPolicyTag($policyTag); + $expectedResponse->setName($name2); + $expectedResponse->setDataPolicyId($dataPolicyId); + $transport->addResponse($expectedResponse); + // Mock request + $name = 'name3373707'; + $newDataPolicyId = 'newDataPolicyId-1742039694'; + $request = (new RenameDataPolicyRequest()) + ->setName($name) + ->setNewDataPolicyId($newDataPolicyId); + $response = $gapicClient->renameDataPolicy($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.bigquery.datapolicies.v1.DataPolicyService/RenameDataPolicy', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($name, $actualValue); + $actualValue = $actualRequestObject->getNewDataPolicyId(); + $this->assertProtobufEquals($newDataPolicyId, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function renameDataPolicyExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $name = 'name3373707'; + $newDataPolicyId = 'newDataPolicyId-1742039694'; + $request = (new RenameDataPolicyRequest()) + ->setName($name) + ->setNewDataPolicyId($newDataPolicyId); + try { + $gapicClient->renameDataPolicy($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function setIamPolicyTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $version = 351608024; + $etag = '21'; + $expectedResponse = new Policy(); + $expectedResponse->setVersion($version); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $policy = new Policy(); + $request = (new SetIamPolicyRequest()) + ->setResource($resource) + ->setPolicy($policy); + $response = $gapicClient->setIamPolicy($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.bigquery.datapolicies.v1.DataPolicyService/SetIamPolicy', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $actualValue = $actualRequestObject->getPolicy(); + $this->assertProtobufEquals($policy, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function setIamPolicyExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $resource = 'resource-341064690'; + $policy = new Policy(); + $request = (new SetIamPolicyRequest()) + ->setResource($resource) + ->setPolicy($policy); + try { + $gapicClient->setIamPolicy($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function testIamPermissionsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new TestIamPermissionsResponse(); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $permissions = []; + $request = (new TestIamPermissionsRequest()) + ->setResource($resource) + ->setPermissions($permissions); + $response = $gapicClient->testIamPermissions($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.bigquery.datapolicies.v1.DataPolicyService/TestIamPermissions', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $actualValue = $actualRequestObject->getPermissions(); + $this->assertProtobufEquals($permissions, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function testIamPermissionsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $resource = 'resource-341064690'; + $permissions = []; + $request = (new TestIamPermissionsRequest()) + ->setResource($resource) + ->setPermissions($permissions); + try { + $gapicClient->testIamPermissions($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function updateDataPolicyTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $policyTag = 'policyTag1593879309'; + $name = 'name3373707'; + $dataPolicyId = 'dataPolicyId456934643'; + $expectedResponse = new DataPolicy(); + $expectedResponse->setPolicyTag($policyTag); + $expectedResponse->setName($name); + $expectedResponse->setDataPolicyId($dataPolicyId); + $transport->addResponse($expectedResponse); + // Mock request + $dataPolicy = new DataPolicy(); + $request = (new UpdateDataPolicyRequest()) + ->setDataPolicy($dataPolicy); + $response = $gapicClient->updateDataPolicy($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.bigquery.datapolicies.v1.DataPolicyService/UpdateDataPolicy', $actualFuncCall); + $actualValue = $actualRequestObject->getDataPolicy(); + $this->assertProtobufEquals($dataPolicy, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function updateDataPolicyExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $dataPolicy = new DataPolicy(); + $request = (new UpdateDataPolicyRequest()) + ->setDataPolicy($dataPolicy); + try { + $gapicClient->updateDataPolicy($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createDataPolicyAsyncTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $policyTag = 'policyTag1593879309'; + $name = 'name3373707'; + $dataPolicyId = 'dataPolicyId456934643'; + $expectedResponse = new DataPolicy(); + $expectedResponse->setPolicyTag($policyTag); + $expectedResponse->setName($name); + $expectedResponse->setDataPolicyId($dataPolicyId); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $dataPolicy = new DataPolicy(); + $request = (new CreateDataPolicyRequest()) + ->setParent($formattedParent) + ->setDataPolicy($dataPolicy); + $response = $gapicClient->createDataPolicyAsync($request)->wait(); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.bigquery.datapolicies.v1.DataPolicyService/CreateDataPolicy', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getDataPolicy(); + $this->assertProtobufEquals($dataPolicy, $actualValue); + $this->assertTrue($transport->isExhausted()); + } +} diff --git a/BigQueryMigration/samples/V2/MigrationServiceClient/create_migration_workflow.php b/BigQueryMigration/samples/V2/MigrationServiceClient/create_migration_workflow.php index 5d313c41e368..b6de6ab4a6f4 100644 --- a/BigQueryMigration/samples/V2/MigrationServiceClient/create_migration_workflow.php +++ b/BigQueryMigration/samples/V2/MigrationServiceClient/create_migration_workflow.php @@ -24,7 +24,8 @@ // [START bigquerymigration_v2_generated_MigrationService_CreateMigrationWorkflow_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BigQuery\Migration\V2\MigrationServiceClient; +use Google\Cloud\BigQuery\Migration\V2\Client\MigrationServiceClient; +use Google\Cloud\BigQuery\Migration\V2\CreateMigrationWorkflowRequest; use Google\Cloud\BigQuery\Migration\V2\MigrationWorkflow; /** @@ -39,13 +40,16 @@ function create_migration_workflow_sample(string $formattedParent): void // Create a client. $migrationServiceClient = new MigrationServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $migrationWorkflow = new MigrationWorkflow(); + $request = (new CreateMigrationWorkflowRequest()) + ->setParent($formattedParent) + ->setMigrationWorkflow($migrationWorkflow); // Call the API and handle any network failures. try { /** @var MigrationWorkflow $response */ - $response = $migrationServiceClient->createMigrationWorkflow($formattedParent, $migrationWorkflow); + $response = $migrationServiceClient->createMigrationWorkflow($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BigQueryMigration/samples/V2/MigrationServiceClient/delete_migration_workflow.php b/BigQueryMigration/samples/V2/MigrationServiceClient/delete_migration_workflow.php index 2a96e73b8fac..c3eb604ba1f9 100644 --- a/BigQueryMigration/samples/V2/MigrationServiceClient/delete_migration_workflow.php +++ b/BigQueryMigration/samples/V2/MigrationServiceClient/delete_migration_workflow.php @@ -24,7 +24,8 @@ // [START bigquerymigration_v2_generated_MigrationService_DeleteMigrationWorkflow_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BigQuery\Migration\V2\MigrationServiceClient; +use Google\Cloud\BigQuery\Migration\V2\Client\MigrationServiceClient; +use Google\Cloud\BigQuery\Migration\V2\DeleteMigrationWorkflowRequest; /** * Deletes a migration workflow by name. @@ -38,9 +39,13 @@ function delete_migration_workflow_sample(string $formattedName): void // Create a client. $migrationServiceClient = new MigrationServiceClient(); + // Prepare the request message. + $request = (new DeleteMigrationWorkflowRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { - $migrationServiceClient->deleteMigrationWorkflow($formattedName); + $migrationServiceClient->deleteMigrationWorkflow($request); printf('Call completed successfully.' . PHP_EOL); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BigQueryMigration/samples/V2/MigrationServiceClient/get_migration_subtask.php b/BigQueryMigration/samples/V2/MigrationServiceClient/get_migration_subtask.php index ae4a71250879..e6ffa30a08bf 100644 --- a/BigQueryMigration/samples/V2/MigrationServiceClient/get_migration_subtask.php +++ b/BigQueryMigration/samples/V2/MigrationServiceClient/get_migration_subtask.php @@ -24,7 +24,8 @@ // [START bigquerymigration_v2_generated_MigrationService_GetMigrationSubtask_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BigQuery\Migration\V2\MigrationServiceClient; +use Google\Cloud\BigQuery\Migration\V2\Client\MigrationServiceClient; +use Google\Cloud\BigQuery\Migration\V2\GetMigrationSubtaskRequest; use Google\Cloud\BigQuery\Migration\V2\MigrationSubtask; /** @@ -39,10 +40,14 @@ function get_migration_subtask_sample(string $formattedName): void // Create a client. $migrationServiceClient = new MigrationServiceClient(); + // Prepare the request message. + $request = (new GetMigrationSubtaskRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var MigrationSubtask $response */ - $response = $migrationServiceClient->getMigrationSubtask($formattedName); + $response = $migrationServiceClient->getMigrationSubtask($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BigQueryMigration/samples/V2/MigrationServiceClient/get_migration_workflow.php b/BigQueryMigration/samples/V2/MigrationServiceClient/get_migration_workflow.php index f808a29bcb0b..3b9111960499 100644 --- a/BigQueryMigration/samples/V2/MigrationServiceClient/get_migration_workflow.php +++ b/BigQueryMigration/samples/V2/MigrationServiceClient/get_migration_workflow.php @@ -24,7 +24,8 @@ // [START bigquerymigration_v2_generated_MigrationService_GetMigrationWorkflow_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BigQuery\Migration\V2\MigrationServiceClient; +use Google\Cloud\BigQuery\Migration\V2\Client\MigrationServiceClient; +use Google\Cloud\BigQuery\Migration\V2\GetMigrationWorkflowRequest; use Google\Cloud\BigQuery\Migration\V2\MigrationWorkflow; /** @@ -39,10 +40,14 @@ function get_migration_workflow_sample(string $formattedName): void // Create a client. $migrationServiceClient = new MigrationServiceClient(); + // Prepare the request message. + $request = (new GetMigrationWorkflowRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var MigrationWorkflow $response */ - $response = $migrationServiceClient->getMigrationWorkflow($formattedName); + $response = $migrationServiceClient->getMigrationWorkflow($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BigQueryMigration/samples/V2/MigrationServiceClient/list_migration_subtasks.php b/BigQueryMigration/samples/V2/MigrationServiceClient/list_migration_subtasks.php index f4257b264730..4412c83b4c06 100644 --- a/BigQueryMigration/samples/V2/MigrationServiceClient/list_migration_subtasks.php +++ b/BigQueryMigration/samples/V2/MigrationServiceClient/list_migration_subtasks.php @@ -25,7 +25,8 @@ // [START bigquerymigration_v2_generated_MigrationService_ListMigrationSubtasks_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; -use Google\Cloud\BigQuery\Migration\V2\MigrationServiceClient; +use Google\Cloud\BigQuery\Migration\V2\Client\MigrationServiceClient; +use Google\Cloud\BigQuery\Migration\V2\ListMigrationSubtasksRequest; use Google\Cloud\BigQuery\Migration\V2\MigrationSubtask; /** @@ -40,10 +41,14 @@ function list_migration_subtasks_sample(string $formattedParent): void // Create a client. $migrationServiceClient = new MigrationServiceClient(); + // Prepare the request message. + $request = (new ListMigrationSubtasksRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $migrationServiceClient->listMigrationSubtasks($formattedParent); + $response = $migrationServiceClient->listMigrationSubtasks($request); /** @var MigrationSubtask $element */ foreach ($response as $element) { diff --git a/BigQueryMigration/samples/V2/MigrationServiceClient/list_migration_workflows.php b/BigQueryMigration/samples/V2/MigrationServiceClient/list_migration_workflows.php index 6e94aeb18ece..3200fdeb7acf 100644 --- a/BigQueryMigration/samples/V2/MigrationServiceClient/list_migration_workflows.php +++ b/BigQueryMigration/samples/V2/MigrationServiceClient/list_migration_workflows.php @@ -25,7 +25,8 @@ // [START bigquerymigration_v2_generated_MigrationService_ListMigrationWorkflows_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; -use Google\Cloud\BigQuery\Migration\V2\MigrationServiceClient; +use Google\Cloud\BigQuery\Migration\V2\Client\MigrationServiceClient; +use Google\Cloud\BigQuery\Migration\V2\ListMigrationWorkflowsRequest; use Google\Cloud\BigQuery\Migration\V2\MigrationWorkflow; /** @@ -40,10 +41,14 @@ function list_migration_workflows_sample(string $formattedParent): void // Create a client. $migrationServiceClient = new MigrationServiceClient(); + // Prepare the request message. + $request = (new ListMigrationWorkflowsRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $migrationServiceClient->listMigrationWorkflows($formattedParent); + $response = $migrationServiceClient->listMigrationWorkflows($request); /** @var MigrationWorkflow $element */ foreach ($response as $element) { diff --git a/BigQueryMigration/samples/V2/MigrationServiceClient/start_migration_workflow.php b/BigQueryMigration/samples/V2/MigrationServiceClient/start_migration_workflow.php index 1b8c7bc14006..f761d27a94af 100644 --- a/BigQueryMigration/samples/V2/MigrationServiceClient/start_migration_workflow.php +++ b/BigQueryMigration/samples/V2/MigrationServiceClient/start_migration_workflow.php @@ -24,7 +24,8 @@ // [START bigquerymigration_v2_generated_MigrationService_StartMigrationWorkflow_sync] use Google\ApiCore\ApiException; -use Google\Cloud\BigQuery\Migration\V2\MigrationServiceClient; +use Google\Cloud\BigQuery\Migration\V2\Client\MigrationServiceClient; +use Google\Cloud\BigQuery\Migration\V2\StartMigrationWorkflowRequest; /** * Starts a previously created migration workflow. I.e., the state transitions @@ -41,9 +42,13 @@ function start_migration_workflow_sample(string $formattedName): void // Create a client. $migrationServiceClient = new MigrationServiceClient(); + // Prepare the request message. + $request = (new StartMigrationWorkflowRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { - $migrationServiceClient->startMigrationWorkflow($formattedName); + $migrationServiceClient->startMigrationWorkflow($request); printf('Call completed successfully.' . PHP_EOL); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/BigQueryMigration/src/V2/Client/BaseClient/MigrationServiceBaseClient.php b/BigQueryMigration/src/V2/Client/BaseClient/MigrationServiceBaseClient.php new file mode 100644 index 000000000000..fe72fe6fa111 --- /dev/null +++ b/BigQueryMigration/src/V2/Client/BaseClient/MigrationServiceBaseClient.php @@ -0,0 +1,433 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/migration_service_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/migration_service_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/migration_service_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/migration_service_rest_client_config.php', + ], + ], + ]; + } + + /** + * Formats a string containing the fully-qualified path to represent a location + * resource. + * + * @param string $project + * @param string $location + * + * @return string The formatted location resource. + */ + public static function locationName(string $project, string $location): string + { + return self::getPathTemplate('location')->render([ + 'project' => $project, + 'location' => $location, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a + * migration_subtask resource. + * + * @param string $project + * @param string $location + * @param string $workflow + * @param string $subtask + * + * @return string The formatted migration_subtask resource. + */ + public static function migrationSubtaskName(string $project, string $location, string $workflow, string $subtask): string + { + return self::getPathTemplate('migrationSubtask')->render([ + 'project' => $project, + 'location' => $location, + 'workflow' => $workflow, + 'subtask' => $subtask, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a + * migration_workflow resource. + * + * @param string $project + * @param string $location + * @param string $workflow + * + * @return string The formatted migration_workflow resource. + */ + public static function migrationWorkflowName(string $project, string $location, string $workflow): string + { + return self::getPathTemplate('migrationWorkflow')->render([ + 'project' => $project, + 'location' => $location, + 'workflow' => $workflow, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * Template: Pattern + * - location: projects/{project}/locations/{location} + * - migrationSubtask: projects/{project}/locations/{location}/workflows/{workflow}/subtasks/{subtask} + * - migrationWorkflow: projects/{project}/locations/{location}/workflows/{workflow} + * + * The optional $template argument can be supplied to specify a particular pattern, + * and must match one of the templates listed above. If no $template argument is + * provided, or if the $template argument does not match one of the templates + * listed, then parseName will check each of the supported templates, and return + * the first match. + * + * @param string $formattedName The formatted name string + * @param string $template Optional name of template to match + * + * @return array An associative array from name component IDs to component values. + * + * @throws ValidationException If $formattedName could not be matched. + */ + public static function parseName(string $formattedName, string $template = null): array + { + return self::parseFormattedName($formattedName, $template); + } + + /** + * Constructor. + * + * @param array $options { + * Optional. Options for configuring the service API wrapper. + * + * @type string $apiEndpoint + * The address of the API remote host. May optionally include the port, formatted + * as ":". Default 'bigquerymigration.googleapis.com:443'. + * @type string|array|FetchAuthTokenInterface|CredentialsWrapper $credentials + * The credentials to be used by the client to authorize API calls. This option + * accepts either a path to a credentials file, or a decoded credentials file as a + * PHP array. + * *Advanced usage*: In addition, this option can also accept a pre-constructed + * {@see \Google\Auth\FetchAuthTokenInterface} object or + * {@see \Google\ApiCore\CredentialsWrapper} object. Note that when one of these + * objects are provided, any settings in $credentialsConfig will be ignored. + * @type array $credentialsConfig + * Options used to configure credentials, including auth token caching, for the + * client. For a full list of supporting configuration options, see + * {@see \Google\ApiCore\CredentialsWrapper::build()} . + * @type bool $disableRetries + * Determines whether or not retries defined by the client configuration should be + * disabled. Defaults to `false`. + * @type string|array $clientConfig + * Client method configuration, including retry settings. This option can be either + * a path to a JSON file, or a PHP array containing the decoded JSON data. By + * default this settings points to the default client config file, which is + * provided in the resources folder. + * @type string|TransportInterface $transport + * The transport used for executing network requests. May be either the string + * `rest` or `grpc`. Defaults to `grpc` if gRPC support is detected on the system. + * *Advanced usage*: Additionally, it is possible to pass in an already + * instantiated {@see \Google\ApiCore\Transport\TransportInterface} object. Note + * that when this object is provided, any settings in $transportConfig, and any + * $apiEndpoint setting, will be ignored. + * @type array $transportConfig + * Configuration options that will be used to construct the transport. Options for + * each supported transport type should be passed in a key for that transport. For + * example: + * $transportConfig = [ + * 'grpc' => [...], + * 'rest' => [...], + * ]; + * See the {@see \Google\ApiCore\Transport\GrpcTransport::build()} and + * {@see \Google\ApiCore\Transport\RestTransport::build()} methods for the + * supported options. + * @type callable $clientCertSource + * A callable which returns the client cert as a string. This can be used to + * provide a certificate and private key to the transport layer for mTLS. + * } + * + * @throws ValidationException + */ + public function __construct(array $options = []) + { + $clientOptions = $this->buildClientOptions($options); + $this->setClientOptions($clientOptions); + } + + /** Handles execution of the async variants for each documented method. */ + public function __call($method, $args) + { + if (substr($method, -5) !== 'Async') { + trigger_error('Call to undefined method ' . __CLASS__ . "::$method()", E_USER_ERROR); + } + + array_unshift($args, substr($method, 0, -5)); + return call_user_func_array([$this, 'startAsyncCall'], $args); + } + + /** + * Creates a migration workflow. + * + * The async variant is {@see self::createMigrationWorkflowAsync()} . + * + * @param CreateMigrationWorkflowRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return MigrationWorkflow + * + * @throws ApiException Thrown if the API call fails. + */ + public function createMigrationWorkflow(CreateMigrationWorkflowRequest $request, array $callOptions = []): MigrationWorkflow + { + return $this->startApiCall('CreateMigrationWorkflow', $request, $callOptions)->wait(); + } + + /** + * Deletes a migration workflow by name. + * + * The async variant is {@see self::deleteMigrationWorkflowAsync()} . + * + * @param DeleteMigrationWorkflowRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @throws ApiException Thrown if the API call fails. + */ + public function deleteMigrationWorkflow(DeleteMigrationWorkflowRequest $request, array $callOptions = []): void + { + $this->startApiCall('DeleteMigrationWorkflow', $request, $callOptions)->wait(); + } + + /** + * Gets a previously created migration subtask. + * + * The async variant is {@see self::getMigrationSubtaskAsync()} . + * + * @param GetMigrationSubtaskRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return MigrationSubtask + * + * @throws ApiException Thrown if the API call fails. + */ + public function getMigrationSubtask(GetMigrationSubtaskRequest $request, array $callOptions = []): MigrationSubtask + { + return $this->startApiCall('GetMigrationSubtask', $request, $callOptions)->wait(); + } + + /** + * Gets a previously created migration workflow. + * + * The async variant is {@see self::getMigrationWorkflowAsync()} . + * + * @param GetMigrationWorkflowRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return MigrationWorkflow + * + * @throws ApiException Thrown if the API call fails. + */ + public function getMigrationWorkflow(GetMigrationWorkflowRequest $request, array $callOptions = []): MigrationWorkflow + { + return $this->startApiCall('GetMigrationWorkflow', $request, $callOptions)->wait(); + } + + /** + * Lists previously created migration subtasks. + * + * The async variant is {@see self::listMigrationSubtasksAsync()} . + * + * @param ListMigrationSubtasksRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listMigrationSubtasks(ListMigrationSubtasksRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListMigrationSubtasks', $request, $callOptions); + } + + /** + * Lists previously created migration workflow. + * + * The async variant is {@see self::listMigrationWorkflowsAsync()} . + * + * @param ListMigrationWorkflowsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listMigrationWorkflows(ListMigrationWorkflowsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListMigrationWorkflows', $request, $callOptions); + } + + /** + * Starts a previously created migration workflow. I.e., the state transitions + * from DRAFT to RUNNING. This is a no-op if the state is already RUNNING. + * An error will be signaled if the state is anything other than DRAFT or + * RUNNING. + * + * The async variant is {@see self::startMigrationWorkflowAsync()} . + * + * @param StartMigrationWorkflowRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @throws ApiException Thrown if the API call fails. + */ + public function startMigrationWorkflow(StartMigrationWorkflowRequest $request, array $callOptions = []): void + { + $this->startApiCall('StartMigrationWorkflow', $request, $callOptions)->wait(); + } +} diff --git a/BigQueryMigration/src/V2/Client/MigrationServiceClient.php b/BigQueryMigration/src/V2/Client/MigrationServiceClient.php new file mode 100644 index 000000000000..a391ae3c7b57 --- /dev/null +++ b/BigQueryMigration/src/V2/Client/MigrationServiceClient.php @@ -0,0 +1,40 @@ +setParent($parent) + ->setMigrationWorkflow($migrationWorkflow); + } + /** * Constructor. * diff --git a/BigQueryMigration/src/V2/DeleteMigrationWorkflowRequest.php b/BigQueryMigration/src/V2/DeleteMigrationWorkflowRequest.php index 8ba3c264727d..ef69dd87435e 100644 --- a/BigQueryMigration/src/V2/DeleteMigrationWorkflowRequest.php +++ b/BigQueryMigration/src/V2/DeleteMigrationWorkflowRequest.php @@ -23,6 +23,21 @@ class DeleteMigrationWorkflowRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The unique identifier for the migration workflow. + * Example: `projects/123/locations/us/workflows/1234` + * Please see {@see MigrationServiceClient::migrationWorkflowName()} for help formatting this field. + * + * @return \Google\Cloud\BigQuery\Migration\V2\DeleteMigrationWorkflowRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/BigQueryMigration/src/V2/GetMigrationSubtaskRequest.php b/BigQueryMigration/src/V2/GetMigrationSubtaskRequest.php index 73768a3be162..5627e9519448 100644 --- a/BigQueryMigration/src/V2/GetMigrationSubtaskRequest.php +++ b/BigQueryMigration/src/V2/GetMigrationSubtaskRequest.php @@ -29,6 +29,21 @@ class GetMigrationSubtaskRequest extends \Google\Protobuf\Internal\Message */ private $read_mask = null; + /** + * @param string $name Required. The unique identifier for the migration subtask. + * Example: `projects/123/locations/us/workflows/1234/subtasks/543` + * Please see {@see MigrationServiceClient::migrationSubtaskName()} for help formatting this field. + * + * @return \Google\Cloud\BigQuery\Migration\V2\GetMigrationSubtaskRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/BigQueryMigration/src/V2/GetMigrationWorkflowRequest.php b/BigQueryMigration/src/V2/GetMigrationWorkflowRequest.php index 5445a2c3f287..29cd77620b7b 100644 --- a/BigQueryMigration/src/V2/GetMigrationWorkflowRequest.php +++ b/BigQueryMigration/src/V2/GetMigrationWorkflowRequest.php @@ -29,6 +29,21 @@ class GetMigrationWorkflowRequest extends \Google\Protobuf\Internal\Message */ private $read_mask = null; + /** + * @param string $name Required. The unique identifier for the migration workflow. + * Example: `projects/123/locations/us/workflows/1234` + * Please see {@see MigrationServiceClient::migrationWorkflowName()} for help formatting this field. + * + * @return \Google\Cloud\BigQuery\Migration\V2\GetMigrationWorkflowRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/BigQueryMigration/src/V2/ListMigrationSubtasksRequest.php b/BigQueryMigration/src/V2/ListMigrationSubtasksRequest.php index d05d2c9d8165..f70c040f150b 100644 --- a/BigQueryMigration/src/V2/ListMigrationSubtasksRequest.php +++ b/BigQueryMigration/src/V2/ListMigrationSubtasksRequest.php @@ -53,6 +53,21 @@ class ListMigrationSubtasksRequest extends \Google\Protobuf\Internal\Message */ private $filter = ''; + /** + * @param string $parent Required. The migration task of the subtasks to list. + * Example: `projects/123/locations/us/workflows/1234` + * Please see {@see MigrationServiceClient::migrationWorkflowName()} for help formatting this field. + * + * @return \Google\Cloud\BigQuery\Migration\V2\ListMigrationSubtasksRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/BigQueryMigration/src/V2/ListMigrationWorkflowsRequest.php b/BigQueryMigration/src/V2/ListMigrationWorkflowsRequest.php index 9488202071b1..3e4b4285a52d 100644 --- a/BigQueryMigration/src/V2/ListMigrationWorkflowsRequest.php +++ b/BigQueryMigration/src/V2/ListMigrationWorkflowsRequest.php @@ -45,6 +45,21 @@ class ListMigrationWorkflowsRequest extends \Google\Protobuf\Internal\Message */ private $page_token = ''; + /** + * @param string $parent Required. The project and location of the migration workflows to list. + * Example: `projects/123/locations/us` + * Please see {@see MigrationServiceClient::locationName()} for help formatting this field. + * + * @return \Google\Cloud\BigQuery\Migration\V2\ListMigrationWorkflowsRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/BigQueryMigration/src/V2/StartMigrationWorkflowRequest.php b/BigQueryMigration/src/V2/StartMigrationWorkflowRequest.php index e4a89b8edb27..87188a961f53 100644 --- a/BigQueryMigration/src/V2/StartMigrationWorkflowRequest.php +++ b/BigQueryMigration/src/V2/StartMigrationWorkflowRequest.php @@ -23,6 +23,21 @@ class StartMigrationWorkflowRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The unique identifier for the migration workflow. + * Example: `projects/123/locations/us/workflows/1234` + * Please see {@see MigrationServiceClient::migrationWorkflowName()} for help formatting this field. + * + * @return \Google\Cloud\BigQuery\Migration\V2\StartMigrationWorkflowRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/BigQueryMigration/src/V2/resources/migration_service_descriptor_config.php b/BigQueryMigration/src/V2/resources/migration_service_descriptor_config.php index 5eaacc8068d1..f1301a436a11 100644 --- a/BigQueryMigration/src/V2/resources/migration_service_descriptor_config.php +++ b/BigQueryMigration/src/V2/resources/migration_service_descriptor_config.php @@ -3,6 +3,54 @@ return [ 'interfaces' => [ 'google.cloud.bigquery.migration.v2.MigrationService' => [ + 'CreateMigrationWorkflow' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\BigQuery\Migration\V2\MigrationWorkflow', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'DeleteMigrationWorkflow' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Protobuf\GPBEmpty', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetMigrationSubtask' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\BigQuery\Migration\V2\MigrationSubtask', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetMigrationWorkflow' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\BigQuery\Migration\V2\MigrationWorkflow', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], 'ListMigrationSubtasks' => [ 'pageStreaming' => [ 'requestPageTokenGetMethod' => 'getPageToken', @@ -12,6 +60,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getMigrationSubtasks', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\BigQuery\Migration\V2\ListMigrationSubtasksResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ListMigrationWorkflows' => [ 'pageStreaming' => [ @@ -22,6 +80,33 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getMigrationWorkflows', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\BigQuery\Migration\V2\ListMigrationWorkflowsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'StartMigrationWorkflow' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Protobuf\GPBEmpty', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'templateMap' => [ + 'location' => 'projects/{project}/locations/{location}', + 'migrationSubtask' => 'projects/{project}/locations/{location}/workflows/{workflow}/subtasks/{subtask}', + 'migrationWorkflow' => 'projects/{project}/locations/{location}/workflows/{workflow}', ], ], ], diff --git a/BigQueryMigration/tests/Unit/V2/Client/MigrationServiceClientTest.php b/BigQueryMigration/tests/Unit/V2/Client/MigrationServiceClientTest.php new file mode 100644 index 000000000000..4e996049a967 --- /dev/null +++ b/BigQueryMigration/tests/Unit/V2/Client/MigrationServiceClientTest.php @@ -0,0 +1,581 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return MigrationServiceClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new MigrationServiceClient($options); + } + + /** @test */ + public function createMigrationWorkflowTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $displayName = 'displayName1615086568'; + $expectedResponse = new MigrationWorkflow(); + $expectedResponse->setName($name); + $expectedResponse->setDisplayName($displayName); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $migrationWorkflow = new MigrationWorkflow(); + $request = (new CreateMigrationWorkflowRequest()) + ->setParent($formattedParent) + ->setMigrationWorkflow($migrationWorkflow); + $response = $gapicClient->createMigrationWorkflow($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.bigquery.migration.v2.MigrationService/CreateMigrationWorkflow', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getMigrationWorkflow(); + $this->assertProtobufEquals($migrationWorkflow, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createMigrationWorkflowExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $migrationWorkflow = new MigrationWorkflow(); + $request = (new CreateMigrationWorkflowRequest()) + ->setParent($formattedParent) + ->setMigrationWorkflow($migrationWorkflow); + try { + $gapicClient->createMigrationWorkflow($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteMigrationWorkflowTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new GPBEmpty(); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->migrationWorkflowName('[PROJECT]', '[LOCATION]', '[WORKFLOW]'); + $request = (new DeleteMigrationWorkflowRequest()) + ->setName($formattedName); + $gapicClient->deleteMigrationWorkflow($request); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.bigquery.migration.v2.MigrationService/DeleteMigrationWorkflow', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteMigrationWorkflowExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->migrationWorkflowName('[PROJECT]', '[LOCATION]', '[WORKFLOW]'); + $request = (new DeleteMigrationWorkflowRequest()) + ->setName($formattedName); + try { + $gapicClient->deleteMigrationWorkflow($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getMigrationSubtaskTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $taskId = 'taskId-1537240555'; + $type = 'type3575610'; + $resourceErrorCount = 929997465; + $expectedResponse = new MigrationSubtask(); + $expectedResponse->setName($name2); + $expectedResponse->setTaskId($taskId); + $expectedResponse->setType($type); + $expectedResponse->setResourceErrorCount($resourceErrorCount); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->migrationSubtaskName('[PROJECT]', '[LOCATION]', '[WORKFLOW]', '[SUBTASK]'); + $request = (new GetMigrationSubtaskRequest()) + ->setName($formattedName); + $response = $gapicClient->getMigrationSubtask($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.bigquery.migration.v2.MigrationService/GetMigrationSubtask', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getMigrationSubtaskExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->migrationSubtaskName('[PROJECT]', '[LOCATION]', '[WORKFLOW]', '[SUBTASK]'); + $request = (new GetMigrationSubtaskRequest()) + ->setName($formattedName); + try { + $gapicClient->getMigrationSubtask($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getMigrationWorkflowTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $displayName = 'displayName1615086568'; + $expectedResponse = new MigrationWorkflow(); + $expectedResponse->setName($name2); + $expectedResponse->setDisplayName($displayName); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->migrationWorkflowName('[PROJECT]', '[LOCATION]', '[WORKFLOW]'); + $request = (new GetMigrationWorkflowRequest()) + ->setName($formattedName); + $response = $gapicClient->getMigrationWorkflow($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.bigquery.migration.v2.MigrationService/GetMigrationWorkflow', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getMigrationWorkflowExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->migrationWorkflowName('[PROJECT]', '[LOCATION]', '[WORKFLOW]'); + $request = (new GetMigrationWorkflowRequest()) + ->setName($formattedName); + try { + $gapicClient->getMigrationWorkflow($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listMigrationSubtasksTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $migrationSubtasksElement = new MigrationSubtask(); + $migrationSubtasks = [ + $migrationSubtasksElement, + ]; + $expectedResponse = new ListMigrationSubtasksResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setMigrationSubtasks($migrationSubtasks); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->migrationWorkflowName('[PROJECT]', '[LOCATION]', '[WORKFLOW]'); + $request = (new ListMigrationSubtasksRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listMigrationSubtasks($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getMigrationSubtasks()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.bigquery.migration.v2.MigrationService/ListMigrationSubtasks', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listMigrationSubtasksExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->migrationWorkflowName('[PROJECT]', '[LOCATION]', '[WORKFLOW]'); + $request = (new ListMigrationSubtasksRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listMigrationSubtasks($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listMigrationWorkflowsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $migrationWorkflowsElement = new MigrationWorkflow(); + $migrationWorkflows = [ + $migrationWorkflowsElement, + ]; + $expectedResponse = new ListMigrationWorkflowsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setMigrationWorkflows($migrationWorkflows); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListMigrationWorkflowsRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listMigrationWorkflows($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getMigrationWorkflows()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.bigquery.migration.v2.MigrationService/ListMigrationWorkflows', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listMigrationWorkflowsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListMigrationWorkflowsRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listMigrationWorkflows($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function startMigrationWorkflowTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new GPBEmpty(); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->migrationWorkflowName('[PROJECT]', '[LOCATION]', '[WORKFLOW]'); + $request = (new StartMigrationWorkflowRequest()) + ->setName($formattedName); + $gapicClient->startMigrationWorkflow($request); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.bigquery.migration.v2.MigrationService/StartMigrationWorkflow', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function startMigrationWorkflowExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->migrationWorkflowName('[PROJECT]', '[LOCATION]', '[WORKFLOW]'); + $request = (new StartMigrationWorkflowRequest()) + ->setName($formattedName); + try { + $gapicClient->startMigrationWorkflow($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createMigrationWorkflowAsyncTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $displayName = 'displayName1615086568'; + $expectedResponse = new MigrationWorkflow(); + $expectedResponse->setName($name); + $expectedResponse->setDisplayName($displayName); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $migrationWorkflow = new MigrationWorkflow(); + $request = (new CreateMigrationWorkflowRequest()) + ->setParent($formattedParent) + ->setMigrationWorkflow($migrationWorkflow); + $response = $gapicClient->createMigrationWorkflowAsync($request)->wait(); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.bigquery.migration.v2.MigrationService/CreateMigrationWorkflow', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getMigrationWorkflow(); + $this->assertProtobufEquals($migrationWorkflow, $actualValue); + $this->assertTrue($transport->isExhausted()); + } +} diff --git a/Build/samples/V2/RepositoryManagerClient/batch_create_repositories.php b/Build/samples/V2/RepositoryManagerClient/batch_create_repositories.php index 75c1b5969e6b..bd8eef0debf8 100644 --- a/Build/samples/V2/RepositoryManagerClient/batch_create_repositories.php +++ b/Build/samples/V2/RepositoryManagerClient/batch_create_repositories.php @@ -25,10 +25,11 @@ // [START cloudbuild_v2_generated_RepositoryManager_BatchCreateRepositories_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\Build\V2\BatchCreateRepositoriesRequest; use Google\Cloud\Build\V2\BatchCreateRepositoriesResponse; +use Google\Cloud\Build\V2\Client\RepositoryManagerClient; use Google\Cloud\Build\V2\CreateRepositoryRequest; use Google\Cloud\Build\V2\Repository; -use Google\Cloud\Build\V2\RepositoryManagerClient; use Google\Rpc\Status; /** @@ -58,7 +59,7 @@ function batch_create_repositories_sample( // Create a client. $repositoryManagerClient = new RepositoryManagerClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $requestsRepository = (new Repository()) ->setRemoteUri($requestsRepositoryRemoteUri); $createRepositoryRequest = (new CreateRepositoryRequest()) @@ -66,11 +67,14 @@ function batch_create_repositories_sample( ->setRepository($requestsRepository) ->setRepositoryId($requestsRepositoryId); $requests = [$createRepositoryRequest,]; + $request = (new BatchCreateRepositoriesRequest()) + ->setParent($formattedParent) + ->setRequests($requests); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $repositoryManagerClient->batchCreateRepositories($formattedParent, $requests); + $response = $repositoryManagerClient->batchCreateRepositories($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/Build/samples/V2/RepositoryManagerClient/create_connection.php b/Build/samples/V2/RepositoryManagerClient/create_connection.php index 8a1b5e8e93ff..8b83e8387ccd 100644 --- a/Build/samples/V2/RepositoryManagerClient/create_connection.php +++ b/Build/samples/V2/RepositoryManagerClient/create_connection.php @@ -25,8 +25,9 @@ // [START cloudbuild_v2_generated_RepositoryManager_CreateConnection_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\Build\V2\Client\RepositoryManagerClient; use Google\Cloud\Build\V2\Connection; -use Google\Cloud\Build\V2\RepositoryManagerClient; +use Google\Cloud\Build\V2\CreateConnectionRequest; use Google\Rpc\Status; /** @@ -45,17 +46,17 @@ function create_connection_sample(string $formattedParent, string $connectionId) // Create a client. $repositoryManagerClient = new RepositoryManagerClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $connection = new Connection(); + $request = (new CreateConnectionRequest()) + ->setParent($formattedParent) + ->setConnection($connection) + ->setConnectionId($connectionId); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $repositoryManagerClient->createConnection( - $formattedParent, - $connection, - $connectionId - ); + $response = $repositoryManagerClient->createConnection($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/Build/samples/V2/RepositoryManagerClient/create_repository.php b/Build/samples/V2/RepositoryManagerClient/create_repository.php index 0942338e4198..49155728473e 100644 --- a/Build/samples/V2/RepositoryManagerClient/create_repository.php +++ b/Build/samples/V2/RepositoryManagerClient/create_repository.php @@ -25,8 +25,9 @@ // [START cloudbuild_v2_generated_RepositoryManager_CreateRepository_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\Build\V2\Client\RepositoryManagerClient; +use Google\Cloud\Build\V2\CreateRepositoryRequest; use Google\Cloud\Build\V2\Repository; -use Google\Cloud\Build\V2\RepositoryManagerClient; use Google\Rpc\Status; /** @@ -50,18 +51,18 @@ function create_repository_sample( // Create a client. $repositoryManagerClient = new RepositoryManagerClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $repository = (new Repository()) ->setRemoteUri($repositoryRemoteUri); + $request = (new CreateRepositoryRequest()) + ->setParent($formattedParent) + ->setRepository($repository) + ->setRepositoryId($repositoryId); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $repositoryManagerClient->createRepository( - $formattedParent, - $repository, - $repositoryId - ); + $response = $repositoryManagerClient->createRepository($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/Build/samples/V2/RepositoryManagerClient/delete_connection.php b/Build/samples/V2/RepositoryManagerClient/delete_connection.php index 1d8a5eb974f1..d8364f47874d 100644 --- a/Build/samples/V2/RepositoryManagerClient/delete_connection.php +++ b/Build/samples/V2/RepositoryManagerClient/delete_connection.php @@ -25,7 +25,8 @@ // [START cloudbuild_v2_generated_RepositoryManager_DeleteConnection_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\Build\V2\RepositoryManagerClient; +use Google\Cloud\Build\V2\Client\RepositoryManagerClient; +use Google\Cloud\Build\V2\DeleteConnectionRequest; use Google\Rpc\Status; /** @@ -40,10 +41,14 @@ function delete_connection_sample(string $formattedName): void // Create a client. $repositoryManagerClient = new RepositoryManagerClient(); + // Prepare the request message. + $request = (new DeleteConnectionRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $repositoryManagerClient->deleteConnection($formattedName); + $response = $repositoryManagerClient->deleteConnection($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/Build/samples/V2/RepositoryManagerClient/delete_repository.php b/Build/samples/V2/RepositoryManagerClient/delete_repository.php index cf5a22b4db15..28a2a6ef7286 100644 --- a/Build/samples/V2/RepositoryManagerClient/delete_repository.php +++ b/Build/samples/V2/RepositoryManagerClient/delete_repository.php @@ -25,7 +25,8 @@ // [START cloudbuild_v2_generated_RepositoryManager_DeleteRepository_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\Build\V2\RepositoryManagerClient; +use Google\Cloud\Build\V2\Client\RepositoryManagerClient; +use Google\Cloud\Build\V2\DeleteRepositoryRequest; use Google\Rpc\Status; /** @@ -40,10 +41,14 @@ function delete_repository_sample(string $formattedName): void // Create a client. $repositoryManagerClient = new RepositoryManagerClient(); + // Prepare the request message. + $request = (new DeleteRepositoryRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $repositoryManagerClient->deleteRepository($formattedName); + $response = $repositoryManagerClient->deleteRepository($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/Build/samples/V2/RepositoryManagerClient/fetch_linkable_repositories.php b/Build/samples/V2/RepositoryManagerClient/fetch_linkable_repositories.php index 54e60c1b4b3c..6f16c82006c7 100644 --- a/Build/samples/V2/RepositoryManagerClient/fetch_linkable_repositories.php +++ b/Build/samples/V2/RepositoryManagerClient/fetch_linkable_repositories.php @@ -25,8 +25,9 @@ // [START cloudbuild_v2_generated_RepositoryManager_FetchLinkableRepositories_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; +use Google\Cloud\Build\V2\Client\RepositoryManagerClient; +use Google\Cloud\Build\V2\FetchLinkableRepositoriesRequest; use Google\Cloud\Build\V2\Repository; -use Google\Cloud\Build\V2\RepositoryManagerClient; /** * FetchLinkableRepositories get repositories from SCM that are @@ -41,10 +42,14 @@ function fetch_linkable_repositories_sample(string $formattedConnection): void // Create a client. $repositoryManagerClient = new RepositoryManagerClient(); + // Prepare the request message. + $request = (new FetchLinkableRepositoriesRequest()) + ->setConnection($formattedConnection); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $repositoryManagerClient->fetchLinkableRepositories($formattedConnection); + $response = $repositoryManagerClient->fetchLinkableRepositories($request); /** @var Repository $element */ foreach ($response as $element) { diff --git a/Build/samples/V2/RepositoryManagerClient/fetch_read_token.php b/Build/samples/V2/RepositoryManagerClient/fetch_read_token.php index f57da799894c..3ff6330d2f0f 100644 --- a/Build/samples/V2/RepositoryManagerClient/fetch_read_token.php +++ b/Build/samples/V2/RepositoryManagerClient/fetch_read_token.php @@ -24,8 +24,9 @@ // [START cloudbuild_v2_generated_RepositoryManager_FetchReadToken_sync] use Google\ApiCore\ApiException; +use Google\Cloud\Build\V2\Client\RepositoryManagerClient; +use Google\Cloud\Build\V2\FetchReadTokenRequest; use Google\Cloud\Build\V2\FetchReadTokenResponse; -use Google\Cloud\Build\V2\RepositoryManagerClient; /** * Fetches read token of a given repository. @@ -39,10 +40,14 @@ function fetch_read_token_sample(string $formattedRepository): void // Create a client. $repositoryManagerClient = new RepositoryManagerClient(); + // Prepare the request message. + $request = (new FetchReadTokenRequest()) + ->setRepository($formattedRepository); + // Call the API and handle any network failures. try { /** @var FetchReadTokenResponse $response */ - $response = $repositoryManagerClient->fetchReadToken($formattedRepository); + $response = $repositoryManagerClient->fetchReadToken($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/Build/samples/V2/RepositoryManagerClient/fetch_read_write_token.php b/Build/samples/V2/RepositoryManagerClient/fetch_read_write_token.php index 51ca8ba3057c..9a3772b2a0c1 100644 --- a/Build/samples/V2/RepositoryManagerClient/fetch_read_write_token.php +++ b/Build/samples/V2/RepositoryManagerClient/fetch_read_write_token.php @@ -24,8 +24,9 @@ // [START cloudbuild_v2_generated_RepositoryManager_FetchReadWriteToken_sync] use Google\ApiCore\ApiException; +use Google\Cloud\Build\V2\Client\RepositoryManagerClient; +use Google\Cloud\Build\V2\FetchReadWriteTokenRequest; use Google\Cloud\Build\V2\FetchReadWriteTokenResponse; -use Google\Cloud\Build\V2\RepositoryManagerClient; /** * Fetches read/write token of a given repository. @@ -39,10 +40,14 @@ function fetch_read_write_token_sample(string $formattedRepository): void // Create a client. $repositoryManagerClient = new RepositoryManagerClient(); + // Prepare the request message. + $request = (new FetchReadWriteTokenRequest()) + ->setRepository($formattedRepository); + // Call the API and handle any network failures. try { /** @var FetchReadWriteTokenResponse $response */ - $response = $repositoryManagerClient->fetchReadWriteToken($formattedRepository); + $response = $repositoryManagerClient->fetchReadWriteToken($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/Build/samples/V2/RepositoryManagerClient/get_connection.php b/Build/samples/V2/RepositoryManagerClient/get_connection.php index 89ca0b8b1410..9792ba919cb0 100644 --- a/Build/samples/V2/RepositoryManagerClient/get_connection.php +++ b/Build/samples/V2/RepositoryManagerClient/get_connection.php @@ -24,8 +24,9 @@ // [START cloudbuild_v2_generated_RepositoryManager_GetConnection_sync] use Google\ApiCore\ApiException; +use Google\Cloud\Build\V2\Client\RepositoryManagerClient; use Google\Cloud\Build\V2\Connection; -use Google\Cloud\Build\V2\RepositoryManagerClient; +use Google\Cloud\Build\V2\GetConnectionRequest; /** * Gets details of a single connection. @@ -39,10 +40,14 @@ function get_connection_sample(string $formattedName): void // Create a client. $repositoryManagerClient = new RepositoryManagerClient(); + // Prepare the request message. + $request = (new GetConnectionRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var Connection $response */ - $response = $repositoryManagerClient->getConnection($formattedName); + $response = $repositoryManagerClient->getConnection($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/Build/samples/V2/RepositoryManagerClient/get_iam_policy.php b/Build/samples/V2/RepositoryManagerClient/get_iam_policy.php index 55f48a299d5a..a9fbed2d0ef2 100644 --- a/Build/samples/V2/RepositoryManagerClient/get_iam_policy.php +++ b/Build/samples/V2/RepositoryManagerClient/get_iam_policy.php @@ -24,7 +24,8 @@ // [START cloudbuild_v2_generated_RepositoryManager_GetIamPolicy_sync] use Google\ApiCore\ApiException; -use Google\Cloud\Build\V2\RepositoryManagerClient; +use Google\Cloud\Build\V2\Client\RepositoryManagerClient; +use Google\Cloud\Iam\V1\GetIamPolicyRequest; use Google\Cloud\Iam\V1\Policy; /** @@ -39,10 +40,14 @@ function get_iam_policy_sample(string $resource): void // Create a client. $repositoryManagerClient = new RepositoryManagerClient(); + // Prepare the request message. + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + // Call the API and handle any network failures. try { /** @var Policy $response */ - $response = $repositoryManagerClient->getIamPolicy($resource); + $response = $repositoryManagerClient->getIamPolicy($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/Build/samples/V2/RepositoryManagerClient/get_repository.php b/Build/samples/V2/RepositoryManagerClient/get_repository.php index fb7c68caef01..4020e1517ff2 100644 --- a/Build/samples/V2/RepositoryManagerClient/get_repository.php +++ b/Build/samples/V2/RepositoryManagerClient/get_repository.php @@ -24,8 +24,9 @@ // [START cloudbuild_v2_generated_RepositoryManager_GetRepository_sync] use Google\ApiCore\ApiException; +use Google\Cloud\Build\V2\Client\RepositoryManagerClient; +use Google\Cloud\Build\V2\GetRepositoryRequest; use Google\Cloud\Build\V2\Repository; -use Google\Cloud\Build\V2\RepositoryManagerClient; /** * Gets details of a single repository. @@ -39,10 +40,14 @@ function get_repository_sample(string $formattedName): void // Create a client. $repositoryManagerClient = new RepositoryManagerClient(); + // Prepare the request message. + $request = (new GetRepositoryRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var Repository $response */ - $response = $repositoryManagerClient->getRepository($formattedName); + $response = $repositoryManagerClient->getRepository($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/Build/samples/V2/RepositoryManagerClient/list_connections.php b/Build/samples/V2/RepositoryManagerClient/list_connections.php index 00a8f81a86fc..f19df83f4226 100644 --- a/Build/samples/V2/RepositoryManagerClient/list_connections.php +++ b/Build/samples/V2/RepositoryManagerClient/list_connections.php @@ -25,8 +25,9 @@ // [START cloudbuild_v2_generated_RepositoryManager_ListConnections_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; +use Google\Cloud\Build\V2\Client\RepositoryManagerClient; use Google\Cloud\Build\V2\Connection; -use Google\Cloud\Build\V2\RepositoryManagerClient; +use Google\Cloud\Build\V2\ListConnectionsRequest; /** * Lists Connections in a given project and location. @@ -40,10 +41,14 @@ function list_connections_sample(string $formattedParent): void // Create a client. $repositoryManagerClient = new RepositoryManagerClient(); + // Prepare the request message. + $request = (new ListConnectionsRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $repositoryManagerClient->listConnections($formattedParent); + $response = $repositoryManagerClient->listConnections($request); /** @var Connection $element */ foreach ($response as $element) { diff --git a/Build/samples/V2/RepositoryManagerClient/list_repositories.php b/Build/samples/V2/RepositoryManagerClient/list_repositories.php index c78f520f6f85..0b414ecde898 100644 --- a/Build/samples/V2/RepositoryManagerClient/list_repositories.php +++ b/Build/samples/V2/RepositoryManagerClient/list_repositories.php @@ -25,8 +25,9 @@ // [START cloudbuild_v2_generated_RepositoryManager_ListRepositories_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; +use Google\Cloud\Build\V2\Client\RepositoryManagerClient; +use Google\Cloud\Build\V2\ListRepositoriesRequest; use Google\Cloud\Build\V2\Repository; -use Google\Cloud\Build\V2\RepositoryManagerClient; /** * Lists Repositories in a given connection. @@ -40,10 +41,14 @@ function list_repositories_sample(string $formattedParent): void // Create a client. $repositoryManagerClient = new RepositoryManagerClient(); + // Prepare the request message. + $request = (new ListRepositoriesRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $repositoryManagerClient->listRepositories($formattedParent); + $response = $repositoryManagerClient->listRepositories($request); /** @var Repository $element */ foreach ($response as $element) { diff --git a/Build/samples/V2/RepositoryManagerClient/set_iam_policy.php b/Build/samples/V2/RepositoryManagerClient/set_iam_policy.php index 9118eede4608..2937d2590e92 100644 --- a/Build/samples/V2/RepositoryManagerClient/set_iam_policy.php +++ b/Build/samples/V2/RepositoryManagerClient/set_iam_policy.php @@ -24,8 +24,9 @@ // [START cloudbuild_v2_generated_RepositoryManager_SetIamPolicy_sync] use Google\ApiCore\ApiException; -use Google\Cloud\Build\V2\RepositoryManagerClient; +use Google\Cloud\Build\V2\Client\RepositoryManagerClient; use Google\Cloud\Iam\V1\Policy; +use Google\Cloud\Iam\V1\SetIamPolicyRequest; /** * Sets the access control policy on the specified resource. Replaces @@ -42,13 +43,16 @@ function set_iam_policy_sample(string $resource): void // Create a client. $repositoryManagerClient = new RepositoryManagerClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $policy = new Policy(); + $request = (new SetIamPolicyRequest()) + ->setResource($resource) + ->setPolicy($policy); // Call the API and handle any network failures. try { /** @var Policy $response */ - $response = $repositoryManagerClient->setIamPolicy($resource, $policy); + $response = $repositoryManagerClient->setIamPolicy($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/Build/samples/V2/RepositoryManagerClient/test_iam_permissions.php b/Build/samples/V2/RepositoryManagerClient/test_iam_permissions.php index 63ba941a5d86..cbad5cee2ce3 100644 --- a/Build/samples/V2/RepositoryManagerClient/test_iam_permissions.php +++ b/Build/samples/V2/RepositoryManagerClient/test_iam_permissions.php @@ -24,7 +24,8 @@ // [START cloudbuild_v2_generated_RepositoryManager_TestIamPermissions_sync] use Google\ApiCore\ApiException; -use Google\Cloud\Build\V2\RepositoryManagerClient; +use Google\Cloud\Build\V2\Client\RepositoryManagerClient; +use Google\Cloud\Iam\V1\TestIamPermissionsRequest; use Google\Cloud\Iam\V1\TestIamPermissionsResponse; /** @@ -48,13 +49,16 @@ function test_iam_permissions_sample(string $resource, string $permissionsElemen // Create a client. $repositoryManagerClient = new RepositoryManagerClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $permissions = [$permissionsElement,]; + $request = (new TestIamPermissionsRequest()) + ->setResource($resource) + ->setPermissions($permissions); // Call the API and handle any network failures. try { /** @var TestIamPermissionsResponse $response */ - $response = $repositoryManagerClient->testIamPermissions($resource, $permissions); + $response = $repositoryManagerClient->testIamPermissions($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/Build/samples/V2/RepositoryManagerClient/update_connection.php b/Build/samples/V2/RepositoryManagerClient/update_connection.php index 0ac518be7fa9..423557d240e3 100644 --- a/Build/samples/V2/RepositoryManagerClient/update_connection.php +++ b/Build/samples/V2/RepositoryManagerClient/update_connection.php @@ -25,8 +25,9 @@ // [START cloudbuild_v2_generated_RepositoryManager_UpdateConnection_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\Build\V2\Client\RepositoryManagerClient; use Google\Cloud\Build\V2\Connection; -use Google\Cloud\Build\V2\RepositoryManagerClient; +use Google\Cloud\Build\V2\UpdateConnectionRequest; use Google\Rpc\Status; /** @@ -43,13 +44,15 @@ function update_connection_sample(): void // Create a client. $repositoryManagerClient = new RepositoryManagerClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $connection = new Connection(); + $request = (new UpdateConnectionRequest()) + ->setConnection($connection); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $repositoryManagerClient->updateConnection($connection); + $response = $repositoryManagerClient->updateConnection($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/Build/src/V2/BatchCreateRepositoriesRequest.php b/Build/src/V2/BatchCreateRepositoriesRequest.php index 10792323370e..256d779a83ee 100644 --- a/Build/src/V2/BatchCreateRepositoriesRequest.php +++ b/Build/src/V2/BatchCreateRepositoriesRequest.php @@ -31,6 +31,25 @@ class BatchCreateRepositoriesRequest extends \Google\Protobuf\Internal\Message */ private $requests; + /** + * @param string $parent Required. The connection to contain all the repositories being created. + * Format: projects/*/locations/*/connections/* + * The parent field in the CreateRepositoryRequest messages + * must either be empty or match this field. Please see + * {@see RepositoryManagerClient::connectionName()} for help formatting this field. + * @param \Google\Cloud\Build\V2\CreateRepositoryRequest[] $requests Required. The request messages specifying the repositories to create. + * + * @return \Google\Cloud\Build\V2\BatchCreateRepositoriesRequest + * + * @experimental + */ + public static function build(string $parent, array $requests): self + { + return (new self()) + ->setParent($parent) + ->setRequests($requests); + } + /** * Constructor. * diff --git a/Build/src/V2/Client/BaseClient/RepositoryManagerBaseClient.php b/Build/src/V2/Client/BaseClient/RepositoryManagerBaseClient.php new file mode 100644 index 000000000000..d9bc7cf20534 --- /dev/null +++ b/Build/src/V2/Client/BaseClient/RepositoryManagerBaseClient.php @@ -0,0 +1,761 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/repository_manager_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/repository_manager_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/repository_manager_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/repository_manager_rest_client_config.php', + ], + ], + ]; + } + + /** + * Return an OperationsClient object with the same endpoint as $this. + * + * @return OperationsClient + */ + public function getOperationsClient() + { + return $this->operationsClient; + } + + /** + * Resume an existing long running operation that was previously started by a long + * running API method. If $methodName is not provided, or does not match a long + * running API method, then the operation can still be resumed, but the + * OperationResponse object will not deserialize the final response. + * + * @param string $operationName The name of the long running operation + * @param string $methodName The name of the method used to start the operation + * + * @return OperationResponse + */ + public function resumeOperation($operationName, $methodName = null) + { + $options = isset($this->descriptors[$methodName]['longRunning']) ? $this->descriptors[$methodName]['longRunning'] : []; + $operation = new OperationResponse($operationName, $this->getOperationsClient(), $options); + $operation->reload(); + return $operation; + } + + /** + * Formats a string containing the fully-qualified path to represent a connection + * resource. + * + * @param string $project + * @param string $location + * @param string $connection + * + * @return string The formatted connection resource. + */ + public static function connectionName(string $project, string $location, string $connection): string + { + return self::getPathTemplate('connection')->render([ + 'project' => $project, + 'location' => $location, + 'connection' => $connection, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a location + * resource. + * + * @param string $project + * @param string $location + * + * @return string The formatted location resource. + */ + public static function locationName(string $project, string $location): string + { + return self::getPathTemplate('location')->render([ + 'project' => $project, + 'location' => $location, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a repository + * resource. + * + * @param string $project + * @param string $location + * @param string $connection + * @param string $repository + * + * @return string The formatted repository resource. + */ + public static function repositoryName(string $project, string $location, string $connection, string $repository): string + { + return self::getPathTemplate('repository')->render([ + 'project' => $project, + 'location' => $location, + 'connection' => $connection, + 'repository' => $repository, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a + * secret_version resource. + * + * @param string $project + * @param string $secret + * @param string $version + * + * @return string The formatted secret_version resource. + */ + public static function secretVersionName(string $project, string $secret, string $version): string + { + return self::getPathTemplate('secretVersion')->render([ + 'project' => $project, + 'secret' => $secret, + 'version' => $version, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a service + * resource. + * + * @param string $project + * @param string $location + * @param string $namespace + * @param string $service + * + * @return string The formatted service resource. + */ + public static function serviceName(string $project, string $location, string $namespace, string $service): string + { + return self::getPathTemplate('service')->render([ + 'project' => $project, + 'location' => $location, + 'namespace' => $namespace, + 'service' => $service, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * Template: Pattern + * - connection: projects/{project}/locations/{location}/connections/{connection} + * - location: projects/{project}/locations/{location} + * - repository: projects/{project}/locations/{location}/connections/{connection}/repositories/{repository} + * - secretVersion: projects/{project}/secrets/{secret}/versions/{version} + * - service: projects/{project}/locations/{location}/namespaces/{namespace}/services/{service} + * + * The optional $template argument can be supplied to specify a particular pattern, + * and must match one of the templates listed above. If no $template argument is + * provided, or if the $template argument does not match one of the templates + * listed, then parseName will check each of the supported templates, and return + * the first match. + * + * @param string $formattedName The formatted name string + * @param string $template Optional name of template to match + * + * @return array An associative array from name component IDs to component values. + * + * @throws ValidationException If $formattedName could not be matched. + */ + public static function parseName(string $formattedName, string $template = null): array + { + return self::parseFormattedName($formattedName, $template); + } + + /** + * Constructor. + * + * @param array $options { + * Optional. Options for configuring the service API wrapper. + * + * @type string $apiEndpoint + * The address of the API remote host. May optionally include the port, formatted + * as ":". Default 'cloudbuild.googleapis.com:443'. + * @type string|array|FetchAuthTokenInterface|CredentialsWrapper $credentials + * The credentials to be used by the client to authorize API calls. This option + * accepts either a path to a credentials file, or a decoded credentials file as a + * PHP array. + * *Advanced usage*: In addition, this option can also accept a pre-constructed + * {@see \Google\Auth\FetchAuthTokenInterface} object or + * {@see \Google\ApiCore\CredentialsWrapper} object. Note that when one of these + * objects are provided, any settings in $credentialsConfig will be ignored. + * @type array $credentialsConfig + * Options used to configure credentials, including auth token caching, for the + * client. For a full list of supporting configuration options, see + * {@see \Google\ApiCore\CredentialsWrapper::build()} . + * @type bool $disableRetries + * Determines whether or not retries defined by the client configuration should be + * disabled. Defaults to `false`. + * @type string|array $clientConfig + * Client method configuration, including retry settings. This option can be either + * a path to a JSON file, or a PHP array containing the decoded JSON data. By + * default this settings points to the default client config file, which is + * provided in the resources folder. + * @type string|TransportInterface $transport + * The transport used for executing network requests. May be either the string + * `rest` or `grpc`. Defaults to `grpc` if gRPC support is detected on the system. + * *Advanced usage*: Additionally, it is possible to pass in an already + * instantiated {@see \Google\ApiCore\Transport\TransportInterface} object. Note + * that when this object is provided, any settings in $transportConfig, and any + * $apiEndpoint setting, will be ignored. + * @type array $transportConfig + * Configuration options that will be used to construct the transport. Options for + * each supported transport type should be passed in a key for that transport. For + * example: + * $transportConfig = [ + * 'grpc' => [...], + * 'rest' => [...], + * ]; + * See the {@see \Google\ApiCore\Transport\GrpcTransport::build()} and + * {@see \Google\ApiCore\Transport\RestTransport::build()} methods for the + * supported options. + * @type callable $clientCertSource + * A callable which returns the client cert as a string. This can be used to + * provide a certificate and private key to the transport layer for mTLS. + * } + * + * @throws ValidationException + */ + public function __construct(array $options = []) + { + $clientOptions = $this->buildClientOptions($options); + $this->setClientOptions($clientOptions); + $this->operationsClient = $this->createOperationsClient($clientOptions); + } + + /** Handles execution of the async variants for each documented method. */ + public function __call($method, $args) + { + if (substr($method, -5) !== 'Async') { + trigger_error('Call to undefined method ' . __CLASS__ . "::$method()", E_USER_ERROR); + } + + array_unshift($args, substr($method, 0, -5)); + return call_user_func_array([$this, 'startAsyncCall'], $args); + } + + /** + * Creates multiple repositories inside a connection. + * + * The async variant is {@see self::batchCreateRepositoriesAsync()} . + * + * @param BatchCreateRepositoriesRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function batchCreateRepositories(BatchCreateRepositoriesRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('BatchCreateRepositories', $request, $callOptions)->wait(); + } + + /** + * Creates a Connection. + * + * The async variant is {@see self::createConnectionAsync()} . + * + * @param CreateConnectionRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function createConnection(CreateConnectionRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('CreateConnection', $request, $callOptions)->wait(); + } + + /** + * Creates a Repository. + * + * The async variant is {@see self::createRepositoryAsync()} . + * + * @param CreateRepositoryRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function createRepository(CreateRepositoryRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('CreateRepository', $request, $callOptions)->wait(); + } + + /** + * Deletes a single connection. + * + * The async variant is {@see self::deleteConnectionAsync()} . + * + * @param DeleteConnectionRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function deleteConnection(DeleteConnectionRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('DeleteConnection', $request, $callOptions)->wait(); + } + + /** + * Deletes a single repository. + * + * The async variant is {@see self::deleteRepositoryAsync()} . + * + * @param DeleteRepositoryRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function deleteRepository(DeleteRepositoryRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('DeleteRepository', $request, $callOptions)->wait(); + } + + /** + * FetchLinkableRepositories get repositories from SCM that are + * accessible and could be added to the connection. + * + * The async variant is {@see self::fetchLinkableRepositoriesAsync()} . + * + * @param FetchLinkableRepositoriesRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function fetchLinkableRepositories(FetchLinkableRepositoriesRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('FetchLinkableRepositories', $request, $callOptions); + } + + /** + * Fetches read token of a given repository. + * + * The async variant is {@see self::fetchReadTokenAsync()} . + * + * @param FetchReadTokenRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return FetchReadTokenResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function fetchReadToken(FetchReadTokenRequest $request, array $callOptions = []): FetchReadTokenResponse + { + return $this->startApiCall('FetchReadToken', $request, $callOptions)->wait(); + } + + /** + * Fetches read/write token of a given repository. + * + * The async variant is {@see self::fetchReadWriteTokenAsync()} . + * + * @param FetchReadWriteTokenRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return FetchReadWriteTokenResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function fetchReadWriteToken(FetchReadWriteTokenRequest $request, array $callOptions = []): FetchReadWriteTokenResponse + { + return $this->startApiCall('FetchReadWriteToken', $request, $callOptions)->wait(); + } + + /** + * Gets details of a single connection. + * + * The async variant is {@see self::getConnectionAsync()} . + * + * @param GetConnectionRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Connection + * + * @throws ApiException Thrown if the API call fails. + */ + public function getConnection(GetConnectionRequest $request, array $callOptions = []): Connection + { + return $this->startApiCall('GetConnection', $request, $callOptions)->wait(); + } + + /** + * Gets details of a single repository. + * + * The async variant is {@see self::getRepositoryAsync()} . + * + * @param GetRepositoryRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Repository + * + * @throws ApiException Thrown if the API call fails. + */ + public function getRepository(GetRepositoryRequest $request, array $callOptions = []): Repository + { + return $this->startApiCall('GetRepository', $request, $callOptions)->wait(); + } + + /** + * Lists Connections in a given project and location. + * + * The async variant is {@see self::listConnectionsAsync()} . + * + * @param ListConnectionsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listConnections(ListConnectionsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListConnections', $request, $callOptions); + } + + /** + * Lists Repositories in a given connection. + * + * The async variant is {@see self::listRepositoriesAsync()} . + * + * @param ListRepositoriesRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listRepositories(ListRepositoriesRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListRepositories', $request, $callOptions); + } + + /** + * Updates a single connection. + * + * The async variant is {@see self::updateConnectionAsync()} . + * + * @param UpdateConnectionRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function updateConnection(UpdateConnectionRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('UpdateConnection', $request, $callOptions)->wait(); + } + + /** + * Gets the access control policy for a resource. Returns an empty policy + if the resource exists and does not have a policy set. + * + * The async variant is {@see self::getIamPolicyAsync()} . + * + * @param GetIamPolicyRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Policy + * + * @throws ApiException Thrown if the API call fails. + */ + public function getIamPolicy(GetIamPolicyRequest $request, array $callOptions = []): Policy + { + return $this->startApiCall('GetIamPolicy', $request, $callOptions)->wait(); + } + + /** + * Sets the access control policy on the specified resource. Replaces + any existing policy. + + Can return `NOT_FOUND`, `INVALID_ARGUMENT`, and `PERMISSION_DENIED` + errors. + * + * The async variant is {@see self::setIamPolicyAsync()} . + * + * @param SetIamPolicyRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Policy + * + * @throws ApiException Thrown if the API call fails. + */ + public function setIamPolicy(SetIamPolicyRequest $request, array $callOptions = []): Policy + { + return $this->startApiCall('SetIamPolicy', $request, $callOptions)->wait(); + } + + /** + * Returns permissions that a caller has on the specified resource. If the + resource does not exist, this will return an empty set of + permissions, not a `NOT_FOUND` error. + + Note: This operation is designed to be used for building + permission-aware UIs and command-line tools, not for authorization + checking. This operation may "fail open" without warning. + * + * The async variant is {@see self::testIamPermissionsAsync()} . + * + * @param TestIamPermissionsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return TestIamPermissionsResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function testIamPermissions(TestIamPermissionsRequest $request, array $callOptions = []): TestIamPermissionsResponse + { + return $this->startApiCall('TestIamPermissions', $request, $callOptions)->wait(); + } +} diff --git a/Build/src/V2/Client/RepositoryManagerClient.php b/Build/src/V2/Client/RepositoryManagerClient.php new file mode 100644 index 000000000000..3d202c1cee2a --- /dev/null +++ b/Build/src/V2/Client/RepositoryManagerClient.php @@ -0,0 +1,40 @@ +setParent($parent) + ->setConnection($connection) + ->setConnectionId($connectionId); + } + /** * Constructor. * diff --git a/Build/src/V2/CreateRepositoryRequest.php b/Build/src/V2/CreateRepositoryRequest.php index 199eab7b863c..27e44315aa9b 100644 --- a/Build/src/V2/CreateRepositoryRequest.php +++ b/Build/src/V2/CreateRepositoryRequest.php @@ -39,6 +39,29 @@ class CreateRepositoryRequest extends \Google\Protobuf\Internal\Message */ private $repository_id = ''; + /** + * @param string $parent Required. The connection to contain the repository. If the request is part + * of a BatchCreateRepositoriesRequest, this field should be empty or match + * the parent specified there. Please see + * {@see RepositoryManagerClient::connectionName()} for help formatting this field. + * @param \Google\Cloud\Build\V2\Repository $repository Required. The repository to create. + * @param string $repositoryId Required. The ID to use for the repository, which will become the final + * component of the repository's resource name. This ID should be unique in + * the connection. Allows alphanumeric characters and any of + * -._~%!$&'()*+,;=@. + * + * @return \Google\Cloud\Build\V2\CreateRepositoryRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\Build\V2\Repository $repository, string $repositoryId): self + { + return (new self()) + ->setParent($parent) + ->setRepository($repository) + ->setRepositoryId($repositoryId); + } + /** * Constructor. * diff --git a/Build/src/V2/DeleteConnectionRequest.php b/Build/src/V2/DeleteConnectionRequest.php index 4391af958c12..e054f29cf7e3 100644 --- a/Build/src/V2/DeleteConnectionRequest.php +++ b/Build/src/V2/DeleteConnectionRequest.php @@ -37,6 +37,21 @@ class DeleteConnectionRequest extends \Google\Protobuf\Internal\Message */ private $validate_only = false; + /** + * @param string $name Required. The name of the Connection to delete. + * Format: `projects/*/locations/*/connections/*`. Please see + * {@see RepositoryManagerClient::connectionName()} for help formatting this field. + * + * @return \Google\Cloud\Build\V2\DeleteConnectionRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/Build/src/V2/DeleteRepositoryRequest.php b/Build/src/V2/DeleteRepositoryRequest.php index 16dd63021190..1bb8842af7c3 100644 --- a/Build/src/V2/DeleteRepositoryRequest.php +++ b/Build/src/V2/DeleteRepositoryRequest.php @@ -37,6 +37,21 @@ class DeleteRepositoryRequest extends \Google\Protobuf\Internal\Message */ private $validate_only = false; + /** + * @param string $name Required. The name of the Repository to delete. + * Format: `projects/*/locations/*/connections/*/repositories/*`. Please see + * {@see RepositoryManagerClient::repositoryName()} for help formatting this field. + * + * @return \Google\Cloud\Build\V2\DeleteRepositoryRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/Build/src/V2/FetchReadTokenRequest.php b/Build/src/V2/FetchReadTokenRequest.php index d5b9497a7079..ebd949ec1c8d 100644 --- a/Build/src/V2/FetchReadTokenRequest.php +++ b/Build/src/V2/FetchReadTokenRequest.php @@ -23,6 +23,21 @@ class FetchReadTokenRequest extends \Google\Protobuf\Internal\Message */ private $repository = ''; + /** + * @param string $repository Required. The resource name of the repository in the format + * `projects/*/locations/*/connections/*/repositories/*`. Please see + * {@see RepositoryManagerClient::repositoryName()} for help formatting this field. + * + * @return \Google\Cloud\Build\V2\FetchReadTokenRequest + * + * @experimental + */ + public static function build(string $repository): self + { + return (new self()) + ->setRepository($repository); + } + /** * Constructor. * diff --git a/Build/src/V2/FetchReadWriteTokenRequest.php b/Build/src/V2/FetchReadWriteTokenRequest.php index 42c2178d92f6..7d0ba66e6169 100644 --- a/Build/src/V2/FetchReadWriteTokenRequest.php +++ b/Build/src/V2/FetchReadWriteTokenRequest.php @@ -23,6 +23,21 @@ class FetchReadWriteTokenRequest extends \Google\Protobuf\Internal\Message */ private $repository = ''; + /** + * @param string $repository Required. The resource name of the repository in the format + * `projects/*/locations/*/connections/*/repositories/*`. Please see + * {@see RepositoryManagerClient::repositoryName()} for help formatting this field. + * + * @return \Google\Cloud\Build\V2\FetchReadWriteTokenRequest + * + * @experimental + */ + public static function build(string $repository): self + { + return (new self()) + ->setRepository($repository); + } + /** * Constructor. * diff --git a/Build/src/V2/GetConnectionRequest.php b/Build/src/V2/GetConnectionRequest.php index 6b373555e5cd..9f3a2ecfe864 100644 --- a/Build/src/V2/GetConnectionRequest.php +++ b/Build/src/V2/GetConnectionRequest.php @@ -23,6 +23,21 @@ class GetConnectionRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The name of the Connection to retrieve. + * Format: `projects/*/locations/*/connections/*`. Please see + * {@see RepositoryManagerClient::connectionName()} for help formatting this field. + * + * @return \Google\Cloud\Build\V2\GetConnectionRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/Build/src/V2/GetRepositoryRequest.php b/Build/src/V2/GetRepositoryRequest.php index 2423d6742aaa..9775609531fa 100644 --- a/Build/src/V2/GetRepositoryRequest.php +++ b/Build/src/V2/GetRepositoryRequest.php @@ -23,6 +23,21 @@ class GetRepositoryRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The name of the Repository to retrieve. + * Format: `projects/*/locations/*/connections/*/repositories/*`. Please see + * {@see RepositoryManagerClient::repositoryName()} for help formatting this field. + * + * @return \Google\Cloud\Build\V2\GetRepositoryRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/Build/src/V2/ListConnectionsRequest.php b/Build/src/V2/ListConnectionsRequest.php index b1cc2c4cea3e..d768d13cf5b9 100644 --- a/Build/src/V2/ListConnectionsRequest.php +++ b/Build/src/V2/ListConnectionsRequest.php @@ -35,6 +35,21 @@ class ListConnectionsRequest extends \Google\Protobuf\Internal\Message */ private $page_token = ''; + /** + * @param string $parent Required. The parent, which owns this collection of Connections. + * Format: `projects/*/locations/*`. Please see + * {@see RepositoryManagerClient::locationName()} for help formatting this field. + * + * @return \Google\Cloud\Build\V2\ListConnectionsRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/Build/src/V2/ListRepositoriesRequest.php b/Build/src/V2/ListRepositoriesRequest.php index 269edf1d5e5c..61d2d1b2b0a3 100644 --- a/Build/src/V2/ListRepositoriesRequest.php +++ b/Build/src/V2/ListRepositoriesRequest.php @@ -44,6 +44,21 @@ class ListRepositoriesRequest extends \Google\Protobuf\Internal\Message */ private $filter = ''; + /** + * @param string $parent Required. The parent, which owns this collection of Repositories. + * Format: `projects/*/locations/*/connections/*`. Please see + * {@see RepositoryManagerClient::connectionName()} for help formatting this field. + * + * @return \Google\Cloud\Build\V2\ListRepositoriesRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/Build/src/V2/UpdateConnectionRequest.php b/Build/src/V2/UpdateConnectionRequest.php index 300c94011b6e..40ee2ccbd838 100644 --- a/Build/src/V2/UpdateConnectionRequest.php +++ b/Build/src/V2/UpdateConnectionRequest.php @@ -46,6 +46,21 @@ class UpdateConnectionRequest extends \Google\Protobuf\Internal\Message */ private $etag = ''; + /** + * @param \Google\Cloud\Build\V2\Connection $connection Required. The Connection to update. + * @param \Google\Protobuf\FieldMask $updateMask The list of fields to be updated. + * + * @return \Google\Cloud\Build\V2\UpdateConnectionRequest + * + * @experimental + */ + public static function build(\Google\Cloud\Build\V2\Connection $connection, \Google\Protobuf\FieldMask $updateMask): self + { + return (new self()) + ->setConnection($connection) + ->setUpdateMask($updateMask); + } + /** * Constructor. * diff --git a/Build/src/V2/resources/repository_manager_descriptor_config.php b/Build/src/V2/resources/repository_manager_descriptor_config.php index 73fcb4ef9f46..ede8e43a278f 100644 --- a/Build/src/V2/resources/repository_manager_descriptor_config.php +++ b/Build/src/V2/resources/repository_manager_descriptor_config.php @@ -12,6 +12,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'CreateConnection' => [ 'longRunning' => [ @@ -22,6 +31,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'CreateRepository' => [ 'longRunning' => [ @@ -32,6 +50,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'DeleteConnection' => [ 'longRunning' => [ @@ -42,6 +69,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'DeleteRepository' => [ 'longRunning' => [ @@ -52,6 +88,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'UpdateConnection' => [ 'longRunning' => [ @@ -62,6 +107,16 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'connection.name', + 'fieldAccessors' => [ + 'getConnection', + 'getName', + ], + ], + ], ], 'FetchLinkableRepositories' => [ 'pageStreaming' => [ @@ -72,6 +127,64 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getRepositories', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\Build\V2\FetchLinkableRepositoriesResponse', + 'headerParams' => [ + [ + 'keyName' => 'connection', + 'fieldAccessors' => [ + 'getConnection', + ], + ], + ], + ], + 'FetchReadToken' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Build\V2\FetchReadTokenResponse', + 'headerParams' => [ + [ + 'keyName' => 'repository', + 'fieldAccessors' => [ + 'getRepository', + ], + ], + ], + ], + 'FetchReadWriteToken' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Build\V2\FetchReadWriteTokenResponse', + 'headerParams' => [ + [ + 'keyName' => 'repository', + 'fieldAccessors' => [ + 'getRepository', + ], + ], + ], + ], + 'GetConnection' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Build\V2\Connection', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetRepository' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Build\V2\Repository', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'ListConnections' => [ 'pageStreaming' => [ @@ -82,6 +195,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getConnections', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\Build\V2\ListConnectionsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ListRepositories' => [ 'pageStreaming' => [ @@ -92,16 +215,63 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getRepositories', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\Build\V2\ListRepositoriesResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'GetIamPolicy' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\Policy', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], 'interfaceOverride' => 'google.iam.v1.IAMPolicy', ], 'SetIamPolicy' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\Policy', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], 'interfaceOverride' => 'google.iam.v1.IAMPolicy', ], 'TestIamPermissions' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\TestIamPermissionsResponse', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], 'interfaceOverride' => 'google.iam.v1.IAMPolicy', ], + 'templateMap' => [ + 'connection' => 'projects/{project}/locations/{location}/connections/{connection}', + 'location' => 'projects/{project}/locations/{location}', + 'repository' => 'projects/{project}/locations/{location}/connections/{connection}/repositories/{repository}', + 'secretVersion' => 'projects/{project}/secrets/{secret}/versions/{version}', + 'service' => 'projects/{project}/locations/{location}/namespaces/{namespace}/services/{service}', + ], ], ], ]; diff --git a/Build/tests/Unit/V2/Client/RepositoryManagerClientTest.php b/Build/tests/Unit/V2/Client/RepositoryManagerClientTest.php new file mode 100644 index 000000000000..e257e48ef54d --- /dev/null +++ b/Build/tests/Unit/V2/Client/RepositoryManagerClientTest.php @@ -0,0 +1,1629 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return RepositoryManagerClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new RepositoryManagerClient($options); + } + + /** @test */ + public function batchCreateRepositoriesTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/batchCreateRepositoriesTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new BatchCreateRepositoriesResponse(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/batchCreateRepositoriesTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->connectionName('[PROJECT]', '[LOCATION]', '[CONNECTION]'); + $requests = []; + $request = (new BatchCreateRepositoriesRequest()) + ->setParent($formattedParent) + ->setRequests($requests); + $response = $gapicClient->batchCreateRepositories($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.devtools.cloudbuild.v2.RepositoryManager/BatchCreateRepositories', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getRequests(); + $this->assertProtobufEquals($requests, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/batchCreateRepositoriesTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function batchCreateRepositoriesExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/batchCreateRepositoriesTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->connectionName('[PROJECT]', '[LOCATION]', '[CONNECTION]'); + $requests = []; + $request = (new BatchCreateRepositoriesRequest()) + ->setParent($formattedParent) + ->setRequests($requests); + $response = $gapicClient->batchCreateRepositories($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/batchCreateRepositoriesTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function createConnectionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/createConnectionTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $disabled = true; + $reconciling = false; + $etag = 'etag3123477'; + $expectedResponse = new Connection(); + $expectedResponse->setName($name); + $expectedResponse->setDisabled($disabled); + $expectedResponse->setReconciling($reconciling); + $expectedResponse->setEtag($etag); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createConnectionTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $connection = new Connection(); + $connectionId = 'connectionId-513204708'; + $request = (new CreateConnectionRequest()) + ->setParent($formattedParent) + ->setConnection($connection) + ->setConnectionId($connectionId); + $response = $gapicClient->createConnection($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.devtools.cloudbuild.v2.RepositoryManager/CreateConnection', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getConnection(); + $this->assertProtobufEquals($connection, $actualValue); + $actualValue = $actualApiRequestObject->getConnectionId(); + $this->assertProtobufEquals($connectionId, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createConnectionTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function createConnectionExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/createConnectionTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $connection = new Connection(); + $connectionId = 'connectionId-513204708'; + $request = (new CreateConnectionRequest()) + ->setParent($formattedParent) + ->setConnection($connection) + ->setConnectionId($connectionId); + $response = $gapicClient->createConnection($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createConnectionTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function createRepositoryTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/createRepositoryTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $remoteUri = 'remoteUri1041652211'; + $etag = 'etag3123477'; + $expectedResponse = new Repository(); + $expectedResponse->setName($name); + $expectedResponse->setRemoteUri($remoteUri); + $expectedResponse->setEtag($etag); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createRepositoryTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->connectionName('[PROJECT]', '[LOCATION]', '[CONNECTION]'); + $repository = new Repository(); + $repositoryRemoteUri = 'repositoryRemoteUri792690460'; + $repository->setRemoteUri($repositoryRemoteUri); + $repositoryId = 'repositoryId1101683248'; + $request = (new CreateRepositoryRequest()) + ->setParent($formattedParent) + ->setRepository($repository) + ->setRepositoryId($repositoryId); + $response = $gapicClient->createRepository($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.devtools.cloudbuild.v2.RepositoryManager/CreateRepository', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getRepository(); + $this->assertProtobufEquals($repository, $actualValue); + $actualValue = $actualApiRequestObject->getRepositoryId(); + $this->assertProtobufEquals($repositoryId, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createRepositoryTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function createRepositoryExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/createRepositoryTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->connectionName('[PROJECT]', '[LOCATION]', '[CONNECTION]'); + $repository = new Repository(); + $repositoryRemoteUri = 'repositoryRemoteUri792690460'; + $repository->setRemoteUri($repositoryRemoteUri); + $repositoryId = 'repositoryId1101683248'; + $request = (new CreateRepositoryRequest()) + ->setParent($formattedParent) + ->setRepository($repository) + ->setRepositoryId($repositoryId); + $response = $gapicClient->createRepository($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createRepositoryTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function deleteConnectionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/deleteConnectionTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new GPBEmpty(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/deleteConnectionTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->connectionName('[PROJECT]', '[LOCATION]', '[CONNECTION]'); + $request = (new DeleteConnectionRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteConnection($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.devtools.cloudbuild.v2.RepositoryManager/DeleteConnection', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteConnectionTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function deleteConnectionExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/deleteConnectionTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->connectionName('[PROJECT]', '[LOCATION]', '[CONNECTION]'); + $request = (new DeleteConnectionRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteConnection($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteConnectionTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function deleteRepositoryTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/deleteRepositoryTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new GPBEmpty(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/deleteRepositoryTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->repositoryName('[PROJECT]', '[LOCATION]', '[CONNECTION]', '[REPOSITORY]'); + $request = (new DeleteRepositoryRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteRepository($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.devtools.cloudbuild.v2.RepositoryManager/DeleteRepository', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteRepositoryTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function deleteRepositoryExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/deleteRepositoryTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->repositoryName('[PROJECT]', '[LOCATION]', '[CONNECTION]', '[REPOSITORY]'); + $request = (new DeleteRepositoryRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteRepository($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteRepositoryTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function fetchLinkableRepositoriesTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $repositoriesElement = new Repository(); + $repositories = [ + $repositoriesElement, + ]; + $expectedResponse = new FetchLinkableRepositoriesResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setRepositories($repositories); + $transport->addResponse($expectedResponse); + // Mock request + $formattedConnection = $gapicClient->connectionName('[PROJECT]', '[LOCATION]', '[CONNECTION]'); + $request = (new FetchLinkableRepositoriesRequest()) + ->setConnection($formattedConnection); + $response = $gapicClient->fetchLinkableRepositories($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getRepositories()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.devtools.cloudbuild.v2.RepositoryManager/FetchLinkableRepositories', $actualFuncCall); + $actualValue = $actualRequestObject->getConnection(); + $this->assertProtobufEquals($formattedConnection, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function fetchLinkableRepositoriesExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedConnection = $gapicClient->connectionName('[PROJECT]', '[LOCATION]', '[CONNECTION]'); + $request = (new FetchLinkableRepositoriesRequest()) + ->setConnection($formattedConnection); + try { + $gapicClient->fetchLinkableRepositories($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function fetchReadTokenTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $token = 'token110541305'; + $expectedResponse = new FetchReadTokenResponse(); + $expectedResponse->setToken($token); + $transport->addResponse($expectedResponse); + // Mock request + $formattedRepository = $gapicClient->repositoryName('[PROJECT]', '[LOCATION]', '[CONNECTION]', '[REPOSITORY]'); + $request = (new FetchReadTokenRequest()) + ->setRepository($formattedRepository); + $response = $gapicClient->fetchReadToken($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.devtools.cloudbuild.v2.RepositoryManager/FetchReadToken', $actualFuncCall); + $actualValue = $actualRequestObject->getRepository(); + $this->assertProtobufEquals($formattedRepository, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function fetchReadTokenExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedRepository = $gapicClient->repositoryName('[PROJECT]', '[LOCATION]', '[CONNECTION]', '[REPOSITORY]'); + $request = (new FetchReadTokenRequest()) + ->setRepository($formattedRepository); + try { + $gapicClient->fetchReadToken($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function fetchReadWriteTokenTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $token = 'token110541305'; + $expectedResponse = new FetchReadWriteTokenResponse(); + $expectedResponse->setToken($token); + $transport->addResponse($expectedResponse); + // Mock request + $formattedRepository = $gapicClient->repositoryName('[PROJECT]', '[LOCATION]', '[CONNECTION]', '[REPOSITORY]'); + $request = (new FetchReadWriteTokenRequest()) + ->setRepository($formattedRepository); + $response = $gapicClient->fetchReadWriteToken($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.devtools.cloudbuild.v2.RepositoryManager/FetchReadWriteToken', $actualFuncCall); + $actualValue = $actualRequestObject->getRepository(); + $this->assertProtobufEquals($formattedRepository, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function fetchReadWriteTokenExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedRepository = $gapicClient->repositoryName('[PROJECT]', '[LOCATION]', '[CONNECTION]', '[REPOSITORY]'); + $request = (new FetchReadWriteTokenRequest()) + ->setRepository($formattedRepository); + try { + $gapicClient->fetchReadWriteToken($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getConnectionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $disabled = true; + $reconciling = false; + $etag = 'etag3123477'; + $expectedResponse = new Connection(); + $expectedResponse->setName($name2); + $expectedResponse->setDisabled($disabled); + $expectedResponse->setReconciling($reconciling); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->connectionName('[PROJECT]', '[LOCATION]', '[CONNECTION]'); + $request = (new GetConnectionRequest()) + ->setName($formattedName); + $response = $gapicClient->getConnection($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.devtools.cloudbuild.v2.RepositoryManager/GetConnection', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getConnectionExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->connectionName('[PROJECT]', '[LOCATION]', '[CONNECTION]'); + $request = (new GetConnectionRequest()) + ->setName($formattedName); + try { + $gapicClient->getConnection($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getRepositoryTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $remoteUri = 'remoteUri1041652211'; + $etag = 'etag3123477'; + $expectedResponse = new Repository(); + $expectedResponse->setName($name2); + $expectedResponse->setRemoteUri($remoteUri); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->repositoryName('[PROJECT]', '[LOCATION]', '[CONNECTION]', '[REPOSITORY]'); + $request = (new GetRepositoryRequest()) + ->setName($formattedName); + $response = $gapicClient->getRepository($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.devtools.cloudbuild.v2.RepositoryManager/GetRepository', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getRepositoryExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->repositoryName('[PROJECT]', '[LOCATION]', '[CONNECTION]', '[REPOSITORY]'); + $request = (new GetRepositoryRequest()) + ->setName($formattedName); + try { + $gapicClient->getRepository($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listConnectionsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $connectionsElement = new Connection(); + $connections = [ + $connectionsElement, + ]; + $expectedResponse = new ListConnectionsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setConnections($connections); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListConnectionsRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listConnections($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getConnections()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.devtools.cloudbuild.v2.RepositoryManager/ListConnections', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listConnectionsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListConnectionsRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listConnections($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listRepositoriesTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $repositoriesElement = new Repository(); + $repositories = [ + $repositoriesElement, + ]; + $expectedResponse = new ListRepositoriesResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setRepositories($repositories); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->connectionName('[PROJECT]', '[LOCATION]', '[CONNECTION]'); + $request = (new ListRepositoriesRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listRepositories($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getRepositories()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.devtools.cloudbuild.v2.RepositoryManager/ListRepositories', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listRepositoriesExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->connectionName('[PROJECT]', '[LOCATION]', '[CONNECTION]'); + $request = (new ListRepositoriesRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listRepositories($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function updateConnectionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/updateConnectionTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $disabled = true; + $reconciling = false; + $etag2 = 'etag2-1293302904'; + $expectedResponse = new Connection(); + $expectedResponse->setName($name); + $expectedResponse->setDisabled($disabled); + $expectedResponse->setReconciling($reconciling); + $expectedResponse->setEtag($etag2); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/updateConnectionTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $connection = new Connection(); + $request = (new UpdateConnectionRequest()) + ->setConnection($connection); + $response = $gapicClient->updateConnection($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.devtools.cloudbuild.v2.RepositoryManager/UpdateConnection', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getConnection(); + $this->assertProtobufEquals($connection, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateConnectionTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function updateConnectionExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/updateConnectionTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $connection = new Connection(); + $request = (new UpdateConnectionRequest()) + ->setConnection($connection); + $response = $gapicClient->updateConnection($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateConnectionTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function getIamPolicyTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $version = 351608024; + $etag = '21'; + $expectedResponse = new Policy(); + $expectedResponse->setVersion($version); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + $response = $gapicClient->getIamPolicy($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.iam.v1.IAMPolicy/GetIamPolicy', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getIamPolicyExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $resource = 'resource-341064690'; + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + try { + $gapicClient->getIamPolicy($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function setIamPolicyTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $version = 351608024; + $etag = '21'; + $expectedResponse = new Policy(); + $expectedResponse->setVersion($version); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $policy = new Policy(); + $request = (new SetIamPolicyRequest()) + ->setResource($resource) + ->setPolicy($policy); + $response = $gapicClient->setIamPolicy($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.iam.v1.IAMPolicy/SetIamPolicy', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $actualValue = $actualRequestObject->getPolicy(); + $this->assertProtobufEquals($policy, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function setIamPolicyExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $resource = 'resource-341064690'; + $policy = new Policy(); + $request = (new SetIamPolicyRequest()) + ->setResource($resource) + ->setPolicy($policy); + try { + $gapicClient->setIamPolicy($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function testIamPermissionsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new TestIamPermissionsResponse(); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $permissions = []; + $request = (new TestIamPermissionsRequest()) + ->setResource($resource) + ->setPermissions($permissions); + $response = $gapicClient->testIamPermissions($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.iam.v1.IAMPolicy/TestIamPermissions', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $actualValue = $actualRequestObject->getPermissions(); + $this->assertProtobufEquals($permissions, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function testIamPermissionsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $resource = 'resource-341064690'; + $permissions = []; + $request = (new TestIamPermissionsRequest()) + ->setResource($resource) + ->setPermissions($permissions); + try { + $gapicClient->testIamPermissions($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function batchCreateRepositoriesAsyncTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/batchCreateRepositoriesTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new BatchCreateRepositoriesResponse(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/batchCreateRepositoriesTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->connectionName('[PROJECT]', '[LOCATION]', '[CONNECTION]'); + $requests = []; + $request = (new BatchCreateRepositoriesRequest()) + ->setParent($formattedParent) + ->setRequests($requests); + $response = $gapicClient->batchCreateRepositoriesAsync($request)->wait(); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.devtools.cloudbuild.v2.RepositoryManager/BatchCreateRepositories', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getRequests(); + $this->assertProtobufEquals($requests, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/batchCreateRepositoriesTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } +} diff --git a/CertificateManager/samples/V1/CertificateManagerClient/create_certificate.php b/CertificateManager/samples/V1/CertificateManagerClient/create_certificate.php index ee7aaf2d6aad..461884c10e74 100644 --- a/CertificateManager/samples/V1/CertificateManagerClient/create_certificate.php +++ b/CertificateManager/samples/V1/CertificateManagerClient/create_certificate.php @@ -26,7 +26,8 @@ use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; use Google\Cloud\CertificateManager\V1\Certificate; -use Google\Cloud\CertificateManager\V1\CertificateManagerClient; +use Google\Cloud\CertificateManager\V1\Client\CertificateManagerClient; +use Google\Cloud\CertificateManager\V1\CreateCertificateRequest; use Google\Rpc\Status; /** @@ -42,17 +43,17 @@ function create_certificate_sample(string $formattedParent, string $certificateI // Create a client. $certificateManagerClient = new CertificateManagerClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $certificate = new Certificate(); + $request = (new CreateCertificateRequest()) + ->setParent($formattedParent) + ->setCertificateId($certificateId) + ->setCertificate($certificate); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $certificateManagerClient->createCertificate( - $formattedParent, - $certificateId, - $certificate - ); + $response = $certificateManagerClient->createCertificate($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/CertificateManager/samples/V1/CertificateManagerClient/create_certificate_issuance_config.php b/CertificateManager/samples/V1/CertificateManagerClient/create_certificate_issuance_config.php index 615ee32a187e..7ba1a7de1bdc 100644 --- a/CertificateManager/samples/V1/CertificateManagerClient/create_certificate_issuance_config.php +++ b/CertificateManager/samples/V1/CertificateManagerClient/create_certificate_issuance_config.php @@ -28,7 +28,8 @@ use Google\Cloud\CertificateManager\V1\CertificateIssuanceConfig; use Google\Cloud\CertificateManager\V1\CertificateIssuanceConfig\CertificateAuthorityConfig; use Google\Cloud\CertificateManager\V1\CertificateIssuanceConfig\KeyAlgorithm; -use Google\Cloud\CertificateManager\V1\CertificateManagerClient; +use Google\Cloud\CertificateManager\V1\Client\CertificateManagerClient; +use Google\Cloud\CertificateManager\V1\CreateCertificateIssuanceConfigRequest; use Google\Protobuf\Duration; use Google\Rpc\Status; @@ -53,7 +54,7 @@ function create_certificate_issuance_config_sample( // Create a client. $certificateManagerClient = new CertificateManagerClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $certificateIssuanceConfigCertificateAuthorityConfig = new CertificateAuthorityConfig(); $certificateIssuanceConfigLifetime = new Duration(); $certificateIssuanceConfig = (new CertificateIssuanceConfig()) @@ -61,15 +62,15 @@ function create_certificate_issuance_config_sample( ->setLifetime($certificateIssuanceConfigLifetime) ->setRotationWindowPercentage($certificateIssuanceConfigRotationWindowPercentage) ->setKeyAlgorithm($certificateIssuanceConfigKeyAlgorithm); + $request = (new CreateCertificateIssuanceConfigRequest()) + ->setParent($formattedParent) + ->setCertificateIssuanceConfigId($certificateIssuanceConfigId) + ->setCertificateIssuanceConfig($certificateIssuanceConfig); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $certificateManagerClient->createCertificateIssuanceConfig( - $formattedParent, - $certificateIssuanceConfigId, - $certificateIssuanceConfig - ); + $response = $certificateManagerClient->createCertificateIssuanceConfig($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/CertificateManager/samples/V1/CertificateManagerClient/create_certificate_map.php b/CertificateManager/samples/V1/CertificateManagerClient/create_certificate_map.php index 0f79f2cf1e3e..409405131e89 100644 --- a/CertificateManager/samples/V1/CertificateManagerClient/create_certificate_map.php +++ b/CertificateManager/samples/V1/CertificateManagerClient/create_certificate_map.php @@ -25,8 +25,9 @@ // [START certificatemanager_v1_generated_CertificateManager_CreateCertificateMap_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\CertificateManager\V1\CertificateManagerClient; use Google\Cloud\CertificateManager\V1\CertificateMap; +use Google\Cloud\CertificateManager\V1\Client\CertificateManagerClient; +use Google\Cloud\CertificateManager\V1\CreateCertificateMapRequest; use Google\Rpc\Status; /** @@ -42,17 +43,17 @@ function create_certificate_map_sample(string $formattedParent, string $certific // Create a client. $certificateManagerClient = new CertificateManagerClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $certificateMap = new CertificateMap(); + $request = (new CreateCertificateMapRequest()) + ->setParent($formattedParent) + ->setCertificateMapId($certificateMapId) + ->setCertificateMap($certificateMap); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $certificateManagerClient->createCertificateMap( - $formattedParent, - $certificateMapId, - $certificateMap - ); + $response = $certificateManagerClient->createCertificateMap($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/CertificateManager/samples/V1/CertificateManagerClient/create_certificate_map_entry.php b/CertificateManager/samples/V1/CertificateManagerClient/create_certificate_map_entry.php index 2419b1d2b82a..a3017b79ab1f 100644 --- a/CertificateManager/samples/V1/CertificateManagerClient/create_certificate_map_entry.php +++ b/CertificateManager/samples/V1/CertificateManagerClient/create_certificate_map_entry.php @@ -25,8 +25,9 @@ // [START certificatemanager_v1_generated_CertificateManager_CreateCertificateMapEntry_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\CertificateManager\V1\CertificateManagerClient; use Google\Cloud\CertificateManager\V1\CertificateMapEntry; +use Google\Cloud\CertificateManager\V1\Client\CertificateManagerClient; +use Google\Cloud\CertificateManager\V1\CreateCertificateMapEntryRequest; use Google\Rpc\Status; /** @@ -44,17 +45,17 @@ function create_certificate_map_entry_sample( // Create a client. $certificateManagerClient = new CertificateManagerClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $certificateMapEntry = new CertificateMapEntry(); + $request = (new CreateCertificateMapEntryRequest()) + ->setParent($formattedParent) + ->setCertificateMapEntryId($certificateMapEntryId) + ->setCertificateMapEntry($certificateMapEntry); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $certificateManagerClient->createCertificateMapEntry( - $formattedParent, - $certificateMapEntryId, - $certificateMapEntry - ); + $response = $certificateManagerClient->createCertificateMapEntry($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/CertificateManager/samples/V1/CertificateManagerClient/create_dns_authorization.php b/CertificateManager/samples/V1/CertificateManagerClient/create_dns_authorization.php index 924da713c22e..2b32506b54e3 100644 --- a/CertificateManager/samples/V1/CertificateManagerClient/create_dns_authorization.php +++ b/CertificateManager/samples/V1/CertificateManagerClient/create_dns_authorization.php @@ -25,7 +25,8 @@ // [START certificatemanager_v1_generated_CertificateManager_CreateDnsAuthorization_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\CertificateManager\V1\CertificateManagerClient; +use Google\Cloud\CertificateManager\V1\Client\CertificateManagerClient; +use Google\Cloud\CertificateManager\V1\CreateDnsAuthorizationRequest; use Google\Cloud\CertificateManager\V1\DnsAuthorization; use Google\Rpc\Status; @@ -49,18 +50,18 @@ function create_dns_authorization_sample( // Create a client. $certificateManagerClient = new CertificateManagerClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $dnsAuthorization = (new DnsAuthorization()) ->setDomain($dnsAuthorizationDomain); + $request = (new CreateDnsAuthorizationRequest()) + ->setParent($formattedParent) + ->setDnsAuthorizationId($dnsAuthorizationId) + ->setDnsAuthorization($dnsAuthorization); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $certificateManagerClient->createDnsAuthorization( - $formattedParent, - $dnsAuthorizationId, - $dnsAuthorization - ); + $response = $certificateManagerClient->createDnsAuthorization($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/CertificateManager/samples/V1/CertificateManagerClient/delete_certificate.php b/CertificateManager/samples/V1/CertificateManagerClient/delete_certificate.php index 77c5fdf14860..f2cc2c517a49 100644 --- a/CertificateManager/samples/V1/CertificateManagerClient/delete_certificate.php +++ b/CertificateManager/samples/V1/CertificateManagerClient/delete_certificate.php @@ -25,7 +25,8 @@ // [START certificatemanager_v1_generated_CertificateManager_DeleteCertificate_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\CertificateManager\V1\CertificateManagerClient; +use Google\Cloud\CertificateManager\V1\Client\CertificateManagerClient; +use Google\Cloud\CertificateManager\V1\DeleteCertificateRequest; use Google\Rpc\Status; /** @@ -40,10 +41,14 @@ function delete_certificate_sample(string $formattedName): void // Create a client. $certificateManagerClient = new CertificateManagerClient(); + // Prepare the request message. + $request = (new DeleteCertificateRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $certificateManagerClient->deleteCertificate($formattedName); + $response = $certificateManagerClient->deleteCertificate($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/CertificateManager/samples/V1/CertificateManagerClient/delete_certificate_issuance_config.php b/CertificateManager/samples/V1/CertificateManagerClient/delete_certificate_issuance_config.php index ab829019fb61..b4eed09913ae 100644 --- a/CertificateManager/samples/V1/CertificateManagerClient/delete_certificate_issuance_config.php +++ b/CertificateManager/samples/V1/CertificateManagerClient/delete_certificate_issuance_config.php @@ -25,7 +25,8 @@ // [START certificatemanager_v1_generated_CertificateManager_DeleteCertificateIssuanceConfig_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\CertificateManager\V1\CertificateManagerClient; +use Google\Cloud\CertificateManager\V1\Client\CertificateManagerClient; +use Google\Cloud\CertificateManager\V1\DeleteCertificateIssuanceConfigRequest; use Google\Rpc\Status; /** @@ -40,10 +41,14 @@ function delete_certificate_issuance_config_sample(string $formattedName): void // Create a client. $certificateManagerClient = new CertificateManagerClient(); + // Prepare the request message. + $request = (new DeleteCertificateIssuanceConfigRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $certificateManagerClient->deleteCertificateIssuanceConfig($formattedName); + $response = $certificateManagerClient->deleteCertificateIssuanceConfig($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/CertificateManager/samples/V1/CertificateManagerClient/delete_certificate_map.php b/CertificateManager/samples/V1/CertificateManagerClient/delete_certificate_map.php index b9236888ba6b..4558b3dd5c84 100644 --- a/CertificateManager/samples/V1/CertificateManagerClient/delete_certificate_map.php +++ b/CertificateManager/samples/V1/CertificateManagerClient/delete_certificate_map.php @@ -25,7 +25,8 @@ // [START certificatemanager_v1_generated_CertificateManager_DeleteCertificateMap_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\CertificateManager\V1\CertificateManagerClient; +use Google\Cloud\CertificateManager\V1\Client\CertificateManagerClient; +use Google\Cloud\CertificateManager\V1\DeleteCertificateMapRequest; use Google\Rpc\Status; /** @@ -42,10 +43,14 @@ function delete_certificate_map_sample(string $formattedName): void // Create a client. $certificateManagerClient = new CertificateManagerClient(); + // Prepare the request message. + $request = (new DeleteCertificateMapRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $certificateManagerClient->deleteCertificateMap($formattedName); + $response = $certificateManagerClient->deleteCertificateMap($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/CertificateManager/samples/V1/CertificateManagerClient/delete_certificate_map_entry.php b/CertificateManager/samples/V1/CertificateManagerClient/delete_certificate_map_entry.php index af251c5895a8..921ae1661298 100644 --- a/CertificateManager/samples/V1/CertificateManagerClient/delete_certificate_map_entry.php +++ b/CertificateManager/samples/V1/CertificateManagerClient/delete_certificate_map_entry.php @@ -25,7 +25,8 @@ // [START certificatemanager_v1_generated_CertificateManager_DeleteCertificateMapEntry_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\CertificateManager\V1\CertificateManagerClient; +use Google\Cloud\CertificateManager\V1\Client\CertificateManagerClient; +use Google\Cloud\CertificateManager\V1\DeleteCertificateMapEntryRequest; use Google\Rpc\Status; /** @@ -40,10 +41,14 @@ function delete_certificate_map_entry_sample(string $formattedName): void // Create a client. $certificateManagerClient = new CertificateManagerClient(); + // Prepare the request message. + $request = (new DeleteCertificateMapEntryRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $certificateManagerClient->deleteCertificateMapEntry($formattedName); + $response = $certificateManagerClient->deleteCertificateMapEntry($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/CertificateManager/samples/V1/CertificateManagerClient/delete_dns_authorization.php b/CertificateManager/samples/V1/CertificateManagerClient/delete_dns_authorization.php index 2fe20b1c850b..be1583059577 100644 --- a/CertificateManager/samples/V1/CertificateManagerClient/delete_dns_authorization.php +++ b/CertificateManager/samples/V1/CertificateManagerClient/delete_dns_authorization.php @@ -25,7 +25,8 @@ // [START certificatemanager_v1_generated_CertificateManager_DeleteDnsAuthorization_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\CertificateManager\V1\CertificateManagerClient; +use Google\Cloud\CertificateManager\V1\Client\CertificateManagerClient; +use Google\Cloud\CertificateManager\V1\DeleteDnsAuthorizationRequest; use Google\Rpc\Status; /** @@ -40,10 +41,14 @@ function delete_dns_authorization_sample(string $formattedName): void // Create a client. $certificateManagerClient = new CertificateManagerClient(); + // Prepare the request message. + $request = (new DeleteDnsAuthorizationRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $certificateManagerClient->deleteDnsAuthorization($formattedName); + $response = $certificateManagerClient->deleteDnsAuthorization($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/CertificateManager/samples/V1/CertificateManagerClient/get_certificate.php b/CertificateManager/samples/V1/CertificateManagerClient/get_certificate.php index 90cbfcc97475..8e3b21d8c656 100644 --- a/CertificateManager/samples/V1/CertificateManagerClient/get_certificate.php +++ b/CertificateManager/samples/V1/CertificateManagerClient/get_certificate.php @@ -25,7 +25,8 @@ // [START certificatemanager_v1_generated_CertificateManager_GetCertificate_sync] use Google\ApiCore\ApiException; use Google\Cloud\CertificateManager\V1\Certificate; -use Google\Cloud\CertificateManager\V1\CertificateManagerClient; +use Google\Cloud\CertificateManager\V1\Client\CertificateManagerClient; +use Google\Cloud\CertificateManager\V1\GetCertificateRequest; /** * Gets details of a single Certificate. @@ -39,10 +40,14 @@ function get_certificate_sample(string $formattedName): void // Create a client. $certificateManagerClient = new CertificateManagerClient(); + // Prepare the request message. + $request = (new GetCertificateRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var Certificate $response */ - $response = $certificateManagerClient->getCertificate($formattedName); + $response = $certificateManagerClient->getCertificate($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/CertificateManager/samples/V1/CertificateManagerClient/get_certificate_issuance_config.php b/CertificateManager/samples/V1/CertificateManagerClient/get_certificate_issuance_config.php index 0f766bb9fa26..b38265363c8e 100644 --- a/CertificateManager/samples/V1/CertificateManagerClient/get_certificate_issuance_config.php +++ b/CertificateManager/samples/V1/CertificateManagerClient/get_certificate_issuance_config.php @@ -25,7 +25,8 @@ // [START certificatemanager_v1_generated_CertificateManager_GetCertificateIssuanceConfig_sync] use Google\ApiCore\ApiException; use Google\Cloud\CertificateManager\V1\CertificateIssuanceConfig; -use Google\Cloud\CertificateManager\V1\CertificateManagerClient; +use Google\Cloud\CertificateManager\V1\Client\CertificateManagerClient; +use Google\Cloud\CertificateManager\V1\GetCertificateIssuanceConfigRequest; /** * Gets details of a single CertificateIssuanceConfig. @@ -39,10 +40,14 @@ function get_certificate_issuance_config_sample(string $formattedName): void // Create a client. $certificateManagerClient = new CertificateManagerClient(); + // Prepare the request message. + $request = (new GetCertificateIssuanceConfigRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var CertificateIssuanceConfig $response */ - $response = $certificateManagerClient->getCertificateIssuanceConfig($formattedName); + $response = $certificateManagerClient->getCertificateIssuanceConfig($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/CertificateManager/samples/V1/CertificateManagerClient/get_certificate_map.php b/CertificateManager/samples/V1/CertificateManagerClient/get_certificate_map.php index 50edaf603958..b3232e3b49cd 100644 --- a/CertificateManager/samples/V1/CertificateManagerClient/get_certificate_map.php +++ b/CertificateManager/samples/V1/CertificateManagerClient/get_certificate_map.php @@ -24,8 +24,9 @@ // [START certificatemanager_v1_generated_CertificateManager_GetCertificateMap_sync] use Google\ApiCore\ApiException; -use Google\Cloud\CertificateManager\V1\CertificateManagerClient; use Google\Cloud\CertificateManager\V1\CertificateMap; +use Google\Cloud\CertificateManager\V1\Client\CertificateManagerClient; +use Google\Cloud\CertificateManager\V1\GetCertificateMapRequest; /** * Gets details of a single CertificateMap. @@ -39,10 +40,14 @@ function get_certificate_map_sample(string $formattedName): void // Create a client. $certificateManagerClient = new CertificateManagerClient(); + // Prepare the request message. + $request = (new GetCertificateMapRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var CertificateMap $response */ - $response = $certificateManagerClient->getCertificateMap($formattedName); + $response = $certificateManagerClient->getCertificateMap($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/CertificateManager/samples/V1/CertificateManagerClient/get_certificate_map_entry.php b/CertificateManager/samples/V1/CertificateManagerClient/get_certificate_map_entry.php index fe3c58338dab..1399106ea7f1 100644 --- a/CertificateManager/samples/V1/CertificateManagerClient/get_certificate_map_entry.php +++ b/CertificateManager/samples/V1/CertificateManagerClient/get_certificate_map_entry.php @@ -24,8 +24,9 @@ // [START certificatemanager_v1_generated_CertificateManager_GetCertificateMapEntry_sync] use Google\ApiCore\ApiException; -use Google\Cloud\CertificateManager\V1\CertificateManagerClient; use Google\Cloud\CertificateManager\V1\CertificateMapEntry; +use Google\Cloud\CertificateManager\V1\Client\CertificateManagerClient; +use Google\Cloud\CertificateManager\V1\GetCertificateMapEntryRequest; /** * Gets details of a single CertificateMapEntry. @@ -39,10 +40,14 @@ function get_certificate_map_entry_sample(string $formattedName): void // Create a client. $certificateManagerClient = new CertificateManagerClient(); + // Prepare the request message. + $request = (new GetCertificateMapEntryRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var CertificateMapEntry $response */ - $response = $certificateManagerClient->getCertificateMapEntry($formattedName); + $response = $certificateManagerClient->getCertificateMapEntry($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/CertificateManager/samples/V1/CertificateManagerClient/get_dns_authorization.php b/CertificateManager/samples/V1/CertificateManagerClient/get_dns_authorization.php index 6a17f2e72255..fd836cd89056 100644 --- a/CertificateManager/samples/V1/CertificateManagerClient/get_dns_authorization.php +++ b/CertificateManager/samples/V1/CertificateManagerClient/get_dns_authorization.php @@ -24,8 +24,9 @@ // [START certificatemanager_v1_generated_CertificateManager_GetDnsAuthorization_sync] use Google\ApiCore\ApiException; -use Google\Cloud\CertificateManager\V1\CertificateManagerClient; +use Google\Cloud\CertificateManager\V1\Client\CertificateManagerClient; use Google\Cloud\CertificateManager\V1\DnsAuthorization; +use Google\Cloud\CertificateManager\V1\GetDnsAuthorizationRequest; /** * Gets details of a single DnsAuthorization. @@ -39,10 +40,14 @@ function get_dns_authorization_sample(string $formattedName): void // Create a client. $certificateManagerClient = new CertificateManagerClient(); + // Prepare the request message. + $request = (new GetDnsAuthorizationRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var DnsAuthorization $response */ - $response = $certificateManagerClient->getDnsAuthorization($formattedName); + $response = $certificateManagerClient->getDnsAuthorization($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/CertificateManager/samples/V1/CertificateManagerClient/get_location.php b/CertificateManager/samples/V1/CertificateManagerClient/get_location.php index a3e8350d2bf6..b5b03ab1d01b 100644 --- a/CertificateManager/samples/V1/CertificateManagerClient/get_location.php +++ b/CertificateManager/samples/V1/CertificateManagerClient/get_location.php @@ -24,7 +24,8 @@ // [START certificatemanager_v1_generated_CertificateManager_GetLocation_sync] use Google\ApiCore\ApiException; -use Google\Cloud\CertificateManager\V1\CertificateManagerClient; +use Google\Cloud\CertificateManager\V1\Client\CertificateManagerClient; +use Google\Cloud\Location\GetLocationRequest; use Google\Cloud\Location\Location; /** @@ -41,10 +42,13 @@ function get_location_sample(): void // Create a client. $certificateManagerClient = new CertificateManagerClient(); + // Prepare the request message. + $request = new GetLocationRequest(); + // Call the API and handle any network failures. try { /** @var Location $response */ - $response = $certificateManagerClient->getLocation(); + $response = $certificateManagerClient->getLocation($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/CertificateManager/samples/V1/CertificateManagerClient/list_certificate_issuance_configs.php b/CertificateManager/samples/V1/CertificateManagerClient/list_certificate_issuance_configs.php index dfc60f117a0b..5efdfcfa1214 100644 --- a/CertificateManager/samples/V1/CertificateManagerClient/list_certificate_issuance_configs.php +++ b/CertificateManager/samples/V1/CertificateManagerClient/list_certificate_issuance_configs.php @@ -26,7 +26,8 @@ use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; use Google\Cloud\CertificateManager\V1\CertificateIssuanceConfig; -use Google\Cloud\CertificateManager\V1\CertificateManagerClient; +use Google\Cloud\CertificateManager\V1\Client\CertificateManagerClient; +use Google\Cloud\CertificateManager\V1\ListCertificateIssuanceConfigsRequest; /** * Lists CertificateIssuanceConfigs in a given project and location. @@ -40,10 +41,14 @@ function list_certificate_issuance_configs_sample(string $formattedParent): void // Create a client. $certificateManagerClient = new CertificateManagerClient(); + // Prepare the request message. + $request = (new ListCertificateIssuanceConfigsRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $certificateManagerClient->listCertificateIssuanceConfigs($formattedParent); + $response = $certificateManagerClient->listCertificateIssuanceConfigs($request); /** @var CertificateIssuanceConfig $element */ foreach ($response as $element) { diff --git a/CertificateManager/samples/V1/CertificateManagerClient/list_certificate_map_entries.php b/CertificateManager/samples/V1/CertificateManagerClient/list_certificate_map_entries.php index 96bcfc3b764f..cae0f6e6a36f 100644 --- a/CertificateManager/samples/V1/CertificateManagerClient/list_certificate_map_entries.php +++ b/CertificateManager/samples/V1/CertificateManagerClient/list_certificate_map_entries.php @@ -25,8 +25,9 @@ // [START certificatemanager_v1_generated_CertificateManager_ListCertificateMapEntries_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; -use Google\Cloud\CertificateManager\V1\CertificateManagerClient; use Google\Cloud\CertificateManager\V1\CertificateMapEntry; +use Google\Cloud\CertificateManager\V1\Client\CertificateManagerClient; +use Google\Cloud\CertificateManager\V1\ListCertificateMapEntriesRequest; /** * Lists CertificateMapEntries in a given project and location. @@ -41,10 +42,14 @@ function list_certificate_map_entries_sample(string $formattedParent): void // Create a client. $certificateManagerClient = new CertificateManagerClient(); + // Prepare the request message. + $request = (new ListCertificateMapEntriesRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $certificateManagerClient->listCertificateMapEntries($formattedParent); + $response = $certificateManagerClient->listCertificateMapEntries($request); /** @var CertificateMapEntry $element */ foreach ($response as $element) { diff --git a/CertificateManager/samples/V1/CertificateManagerClient/list_certificate_maps.php b/CertificateManager/samples/V1/CertificateManagerClient/list_certificate_maps.php index bd65a4358b2c..2cb9837352d8 100644 --- a/CertificateManager/samples/V1/CertificateManagerClient/list_certificate_maps.php +++ b/CertificateManager/samples/V1/CertificateManagerClient/list_certificate_maps.php @@ -25,8 +25,9 @@ // [START certificatemanager_v1_generated_CertificateManager_ListCertificateMaps_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; -use Google\Cloud\CertificateManager\V1\CertificateManagerClient; use Google\Cloud\CertificateManager\V1\CertificateMap; +use Google\Cloud\CertificateManager\V1\Client\CertificateManagerClient; +use Google\Cloud\CertificateManager\V1\ListCertificateMapsRequest; /** * Lists CertificateMaps in a given project and location. @@ -40,10 +41,14 @@ function list_certificate_maps_sample(string $formattedParent): void // Create a client. $certificateManagerClient = new CertificateManagerClient(); + // Prepare the request message. + $request = (new ListCertificateMapsRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $certificateManagerClient->listCertificateMaps($formattedParent); + $response = $certificateManagerClient->listCertificateMaps($request); /** @var CertificateMap $element */ foreach ($response as $element) { diff --git a/CertificateManager/samples/V1/CertificateManagerClient/list_certificates.php b/CertificateManager/samples/V1/CertificateManagerClient/list_certificates.php index bd55163dd80c..11c9925841f1 100644 --- a/CertificateManager/samples/V1/CertificateManagerClient/list_certificates.php +++ b/CertificateManager/samples/V1/CertificateManagerClient/list_certificates.php @@ -26,7 +26,8 @@ use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; use Google\Cloud\CertificateManager\V1\Certificate; -use Google\Cloud\CertificateManager\V1\CertificateManagerClient; +use Google\Cloud\CertificateManager\V1\Client\CertificateManagerClient; +use Google\Cloud\CertificateManager\V1\ListCertificatesRequest; /** * Lists Certificates in a given project and location. @@ -40,10 +41,14 @@ function list_certificates_sample(string $formattedParent): void // Create a client. $certificateManagerClient = new CertificateManagerClient(); + // Prepare the request message. + $request = (new ListCertificatesRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $certificateManagerClient->listCertificates($formattedParent); + $response = $certificateManagerClient->listCertificates($request); /** @var Certificate $element */ foreach ($response as $element) { diff --git a/CertificateManager/samples/V1/CertificateManagerClient/list_dns_authorizations.php b/CertificateManager/samples/V1/CertificateManagerClient/list_dns_authorizations.php index 03c078e604e5..e1ad2500bb21 100644 --- a/CertificateManager/samples/V1/CertificateManagerClient/list_dns_authorizations.php +++ b/CertificateManager/samples/V1/CertificateManagerClient/list_dns_authorizations.php @@ -25,8 +25,9 @@ // [START certificatemanager_v1_generated_CertificateManager_ListDnsAuthorizations_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; -use Google\Cloud\CertificateManager\V1\CertificateManagerClient; +use Google\Cloud\CertificateManager\V1\Client\CertificateManagerClient; use Google\Cloud\CertificateManager\V1\DnsAuthorization; +use Google\Cloud\CertificateManager\V1\ListDnsAuthorizationsRequest; /** * Lists DnsAuthorizations in a given project and location. @@ -40,10 +41,14 @@ function list_dns_authorizations_sample(string $formattedParent): void // Create a client. $certificateManagerClient = new CertificateManagerClient(); + // Prepare the request message. + $request = (new ListDnsAuthorizationsRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $certificateManagerClient->listDnsAuthorizations($formattedParent); + $response = $certificateManagerClient->listDnsAuthorizations($request); /** @var DnsAuthorization $element */ foreach ($response as $element) { diff --git a/CertificateManager/samples/V1/CertificateManagerClient/list_locations.php b/CertificateManager/samples/V1/CertificateManagerClient/list_locations.php index f966e471d87d..38df92f927ed 100644 --- a/CertificateManager/samples/V1/CertificateManagerClient/list_locations.php +++ b/CertificateManager/samples/V1/CertificateManagerClient/list_locations.php @@ -25,7 +25,8 @@ // [START certificatemanager_v1_generated_CertificateManager_ListLocations_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; -use Google\Cloud\CertificateManager\V1\CertificateManagerClient; +use Google\Cloud\CertificateManager\V1\Client\CertificateManagerClient; +use Google\Cloud\Location\ListLocationsRequest; use Google\Cloud\Location\Location; /** @@ -42,10 +43,13 @@ function list_locations_sample(): void // Create a client. $certificateManagerClient = new CertificateManagerClient(); + // Prepare the request message. + $request = new ListLocationsRequest(); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $certificateManagerClient->listLocations(); + $response = $certificateManagerClient->listLocations($request); /** @var Location $element */ foreach ($response as $element) { diff --git a/CertificateManager/samples/V1/CertificateManagerClient/update_certificate.php b/CertificateManager/samples/V1/CertificateManagerClient/update_certificate.php index 4b7956dc8ca3..01ae92819950 100644 --- a/CertificateManager/samples/V1/CertificateManagerClient/update_certificate.php +++ b/CertificateManager/samples/V1/CertificateManagerClient/update_certificate.php @@ -26,7 +26,8 @@ use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; use Google\Cloud\CertificateManager\V1\Certificate; -use Google\Cloud\CertificateManager\V1\CertificateManagerClient; +use Google\Cloud\CertificateManager\V1\Client\CertificateManagerClient; +use Google\Cloud\CertificateManager\V1\UpdateCertificateRequest; use Google\Protobuf\FieldMask; use Google\Rpc\Status; @@ -44,14 +45,17 @@ function update_certificate_sample(): void // Create a client. $certificateManagerClient = new CertificateManagerClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $certificate = new Certificate(); $updateMask = new FieldMask(); + $request = (new UpdateCertificateRequest()) + ->setCertificate($certificate) + ->setUpdateMask($updateMask); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $certificateManagerClient->updateCertificate($certificate, $updateMask); + $response = $certificateManagerClient->updateCertificate($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/CertificateManager/samples/V1/CertificateManagerClient/update_certificate_map.php b/CertificateManager/samples/V1/CertificateManagerClient/update_certificate_map.php index f64ff47edae9..718d913df19d 100644 --- a/CertificateManager/samples/V1/CertificateManagerClient/update_certificate_map.php +++ b/CertificateManager/samples/V1/CertificateManagerClient/update_certificate_map.php @@ -25,8 +25,9 @@ // [START certificatemanager_v1_generated_CertificateManager_UpdateCertificateMap_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\CertificateManager\V1\CertificateManagerClient; use Google\Cloud\CertificateManager\V1\CertificateMap; +use Google\Cloud\CertificateManager\V1\Client\CertificateManagerClient; +use Google\Cloud\CertificateManager\V1\UpdateCertificateMapRequest; use Google\Protobuf\FieldMask; use Google\Rpc\Status; @@ -44,14 +45,17 @@ function update_certificate_map_sample(): void // Create a client. $certificateManagerClient = new CertificateManagerClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $certificateMap = new CertificateMap(); $updateMask = new FieldMask(); + $request = (new UpdateCertificateMapRequest()) + ->setCertificateMap($certificateMap) + ->setUpdateMask($updateMask); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $certificateManagerClient->updateCertificateMap($certificateMap, $updateMask); + $response = $certificateManagerClient->updateCertificateMap($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/CertificateManager/samples/V1/CertificateManagerClient/update_certificate_map_entry.php b/CertificateManager/samples/V1/CertificateManagerClient/update_certificate_map_entry.php index 9fabae5596c3..3f09d0ba7b0d 100644 --- a/CertificateManager/samples/V1/CertificateManagerClient/update_certificate_map_entry.php +++ b/CertificateManager/samples/V1/CertificateManagerClient/update_certificate_map_entry.php @@ -25,8 +25,9 @@ // [START certificatemanager_v1_generated_CertificateManager_UpdateCertificateMapEntry_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\CertificateManager\V1\CertificateManagerClient; use Google\Cloud\CertificateManager\V1\CertificateMapEntry; +use Google\Cloud\CertificateManager\V1\Client\CertificateManagerClient; +use Google\Cloud\CertificateManager\V1\UpdateCertificateMapEntryRequest; use Google\Protobuf\FieldMask; use Google\Rpc\Status; @@ -44,14 +45,17 @@ function update_certificate_map_entry_sample(): void // Create a client. $certificateManagerClient = new CertificateManagerClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $certificateMapEntry = new CertificateMapEntry(); $updateMask = new FieldMask(); + $request = (new UpdateCertificateMapEntryRequest()) + ->setCertificateMapEntry($certificateMapEntry) + ->setUpdateMask($updateMask); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $certificateManagerClient->updateCertificateMapEntry($certificateMapEntry, $updateMask); + $response = $certificateManagerClient->updateCertificateMapEntry($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/CertificateManager/samples/V1/CertificateManagerClient/update_dns_authorization.php b/CertificateManager/samples/V1/CertificateManagerClient/update_dns_authorization.php index 28e38a3b3800..f842db852d8c 100644 --- a/CertificateManager/samples/V1/CertificateManagerClient/update_dns_authorization.php +++ b/CertificateManager/samples/V1/CertificateManagerClient/update_dns_authorization.php @@ -25,8 +25,9 @@ // [START certificatemanager_v1_generated_CertificateManager_UpdateDnsAuthorization_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\CertificateManager\V1\CertificateManagerClient; +use Google\Cloud\CertificateManager\V1\Client\CertificateManagerClient; use Google\Cloud\CertificateManager\V1\DnsAuthorization; +use Google\Cloud\CertificateManager\V1\UpdateDnsAuthorizationRequest; use Google\Protobuf\FieldMask; use Google\Rpc\Status; @@ -43,15 +44,18 @@ function update_dns_authorization_sample(string $dnsAuthorizationDomain): void // Create a client. $certificateManagerClient = new CertificateManagerClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $dnsAuthorization = (new DnsAuthorization()) ->setDomain($dnsAuthorizationDomain); $updateMask = new FieldMask(); + $request = (new UpdateDnsAuthorizationRequest()) + ->setDnsAuthorization($dnsAuthorization) + ->setUpdateMask($updateMask); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $certificateManagerClient->updateDnsAuthorization($dnsAuthorization, $updateMask); + $response = $certificateManagerClient->updateDnsAuthorization($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/CertificateManager/src/V1/Client/BaseClient/CertificateManagerBaseClient.php b/CertificateManager/src/V1/Client/BaseClient/CertificateManagerBaseClient.php new file mode 100644 index 000000000000..41c7627d5a81 --- /dev/null +++ b/CertificateManager/src/V1/Client/BaseClient/CertificateManagerBaseClient.php @@ -0,0 +1,1074 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/certificate_manager_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/certificate_manager_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/certificate_manager_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/certificate_manager_rest_client_config.php', + ], + ], + ]; + } + + /** + * Return an OperationsClient object with the same endpoint as $this. + * + * @return OperationsClient + */ + public function getOperationsClient() + { + return $this->operationsClient; + } + + /** + * Resume an existing long running operation that was previously started by a long + * running API method. If $methodName is not provided, or does not match a long + * running API method, then the operation can still be resumed, but the + * OperationResponse object will not deserialize the final response. + * + * @param string $operationName The name of the long running operation + * @param string $methodName The name of the method used to start the operation + * + * @return OperationResponse + */ + public function resumeOperation($operationName, $methodName = null) + { + $options = isset($this->descriptors[$methodName]['longRunning']) ? $this->descriptors[$methodName]['longRunning'] : []; + $operation = new OperationResponse($operationName, $this->getOperationsClient(), $options); + $operation->reload(); + return $operation; + } + + /** + * Formats a string containing the fully-qualified path to represent a ca_pool + * resource. + * + * @param string $project + * @param string $location + * @param string $caPool + * + * @return string The formatted ca_pool resource. + */ + public static function caPoolName(string $project, string $location, string $caPool): string + { + return self::getPathTemplate('caPool')->render([ + 'project' => $project, + 'location' => $location, + 'ca_pool' => $caPool, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a certificate + * resource. + * + * @param string $project + * @param string $location + * @param string $certificate + * + * @return string The formatted certificate resource. + */ + public static function certificateName(string $project, string $location, string $certificate): string + { + return self::getPathTemplate('certificate')->render([ + 'project' => $project, + 'location' => $location, + 'certificate' => $certificate, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a + * certificate_issuance_config resource. + * + * @param string $project + * @param string $location + * @param string $certificateIssuanceConfig + * + * @return string The formatted certificate_issuance_config resource. + */ + public static function certificateIssuanceConfigName(string $project, string $location, string $certificateIssuanceConfig): string + { + return self::getPathTemplate('certificateIssuanceConfig')->render([ + 'project' => $project, + 'location' => $location, + 'certificate_issuance_config' => $certificateIssuanceConfig, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a + * certificate_map resource. + * + * @param string $project + * @param string $location + * @param string $certificateMap + * + * @return string The formatted certificate_map resource. + */ + public static function certificateMapName(string $project, string $location, string $certificateMap): string + { + return self::getPathTemplate('certificateMap')->render([ + 'project' => $project, + 'location' => $location, + 'certificate_map' => $certificateMap, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a + * certificate_map_entry resource. + * + * @param string $project + * @param string $location + * @param string $certificateMap + * @param string $certificateMapEntry + * + * @return string The formatted certificate_map_entry resource. + */ + public static function certificateMapEntryName(string $project, string $location, string $certificateMap, string $certificateMapEntry): string + { + return self::getPathTemplate('certificateMapEntry')->render([ + 'project' => $project, + 'location' => $location, + 'certificate_map' => $certificateMap, + 'certificate_map_entry' => $certificateMapEntry, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a + * dns_authorization resource. + * + * @param string $project + * @param string $location + * @param string $dnsAuthorization + * + * @return string The formatted dns_authorization resource. + */ + public static function dnsAuthorizationName(string $project, string $location, string $dnsAuthorization): string + { + return self::getPathTemplate('dnsAuthorization')->render([ + 'project' => $project, + 'location' => $location, + 'dns_authorization' => $dnsAuthorization, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a location + * resource. + * + * @param string $project + * @param string $location + * + * @return string The formatted location resource. + */ + public static function locationName(string $project, string $location): string + { + return self::getPathTemplate('location')->render([ + 'project' => $project, + 'location' => $location, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * Template: Pattern + * - caPool: projects/{project}/locations/{location}/caPools/{ca_pool} + * - certificate: projects/{project}/locations/{location}/certificates/{certificate} + * - certificateIssuanceConfig: projects/{project}/locations/{location}/certificateIssuanceConfigs/{certificate_issuance_config} + * - certificateMap: projects/{project}/locations/{location}/certificateMaps/{certificate_map} + * - certificateMapEntry: projects/{project}/locations/{location}/certificateMaps/{certificate_map}/certificateMapEntries/{certificate_map_entry} + * - dnsAuthorization: projects/{project}/locations/{location}/dnsAuthorizations/{dns_authorization} + * - location: projects/{project}/locations/{location} + * + * The optional $template argument can be supplied to specify a particular pattern, + * and must match one of the templates listed above. If no $template argument is + * provided, or if the $template argument does not match one of the templates + * listed, then parseName will check each of the supported templates, and return + * the first match. + * + * @param string $formattedName The formatted name string + * @param string $template Optional name of template to match + * + * @return array An associative array from name component IDs to component values. + * + * @throws ValidationException If $formattedName could not be matched. + */ + public static function parseName(string $formattedName, string $template = null): array + { + return self::parseFormattedName($formattedName, $template); + } + + /** + * Constructor. + * + * @param array $options { + * Optional. Options for configuring the service API wrapper. + * + * @type string $apiEndpoint + * The address of the API remote host. May optionally include the port, formatted + * as ":". Default 'certificatemanager.googleapis.com:443'. + * @type string|array|FetchAuthTokenInterface|CredentialsWrapper $credentials + * The credentials to be used by the client to authorize API calls. This option + * accepts either a path to a credentials file, or a decoded credentials file as a + * PHP array. + * *Advanced usage*: In addition, this option can also accept a pre-constructed + * {@see \Google\Auth\FetchAuthTokenInterface} object or + * {@see \Google\ApiCore\CredentialsWrapper} object. Note that when one of these + * objects are provided, any settings in $credentialsConfig will be ignored. + * @type array $credentialsConfig + * Options used to configure credentials, including auth token caching, for the + * client. For a full list of supporting configuration options, see + * {@see \Google\ApiCore\CredentialsWrapper::build()} . + * @type bool $disableRetries + * Determines whether or not retries defined by the client configuration should be + * disabled. Defaults to `false`. + * @type string|array $clientConfig + * Client method configuration, including retry settings. This option can be either + * a path to a JSON file, or a PHP array containing the decoded JSON data. By + * default this settings points to the default client config file, which is + * provided in the resources folder. + * @type string|TransportInterface $transport + * The transport used for executing network requests. May be either the string + * `rest` or `grpc`. Defaults to `grpc` if gRPC support is detected on the system. + * *Advanced usage*: Additionally, it is possible to pass in an already + * instantiated {@see \Google\ApiCore\Transport\TransportInterface} object. Note + * that when this object is provided, any settings in $transportConfig, and any + * $apiEndpoint setting, will be ignored. + * @type array $transportConfig + * Configuration options that will be used to construct the transport. Options for + * each supported transport type should be passed in a key for that transport. For + * example: + * $transportConfig = [ + * 'grpc' => [...], + * 'rest' => [...], + * ]; + * See the {@see \Google\ApiCore\Transport\GrpcTransport::build()} and + * {@see \Google\ApiCore\Transport\RestTransport::build()} methods for the + * supported options. + * @type callable $clientCertSource + * A callable which returns the client cert as a string. This can be used to + * provide a certificate and private key to the transport layer for mTLS. + * } + * + * @throws ValidationException + */ + public function __construct(array $options = []) + { + $clientOptions = $this->buildClientOptions($options); + $this->setClientOptions($clientOptions); + $this->operationsClient = $this->createOperationsClient($clientOptions); + } + + /** Handles execution of the async variants for each documented method. */ + public function __call($method, $args) + { + if (substr($method, -5) !== 'Async') { + trigger_error('Call to undefined method ' . __CLASS__ . "::$method()", E_USER_ERROR); + } + + array_unshift($args, substr($method, 0, -5)); + return call_user_func_array([$this, 'startAsyncCall'], $args); + } + + /** + * Creates a new Certificate in a given project and location. + * + * The async variant is {@see self::createCertificateAsync()} . + * + * @param CreateCertificateRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function createCertificate(CreateCertificateRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('CreateCertificate', $request, $callOptions)->wait(); + } + + /** + * Creates a new CertificateIssuanceConfig in a given project and location. + * + * The async variant is {@see self::createCertificateIssuanceConfigAsync()} . + * + * @param CreateCertificateIssuanceConfigRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function createCertificateIssuanceConfig(CreateCertificateIssuanceConfigRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('CreateCertificateIssuanceConfig', $request, $callOptions)->wait(); + } + + /** + * Creates a new CertificateMap in a given project and location. + * + * The async variant is {@see self::createCertificateMapAsync()} . + * + * @param CreateCertificateMapRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function createCertificateMap(CreateCertificateMapRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('CreateCertificateMap', $request, $callOptions)->wait(); + } + + /** + * Creates a new CertificateMapEntry in a given project and location. + * + * The async variant is {@see self::createCertificateMapEntryAsync()} . + * + * @param CreateCertificateMapEntryRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function createCertificateMapEntry(CreateCertificateMapEntryRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('CreateCertificateMapEntry', $request, $callOptions)->wait(); + } + + /** + * Creates a new DnsAuthorization in a given project and location. + * + * The async variant is {@see self::createDnsAuthorizationAsync()} . + * + * @param CreateDnsAuthorizationRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function createDnsAuthorization(CreateDnsAuthorizationRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('CreateDnsAuthorization', $request, $callOptions)->wait(); + } + + /** + * Deletes a single Certificate. + * + * The async variant is {@see self::deleteCertificateAsync()} . + * + * @param DeleteCertificateRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function deleteCertificate(DeleteCertificateRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('DeleteCertificate', $request, $callOptions)->wait(); + } + + /** + * Deletes a single CertificateIssuanceConfig. + * + * The async variant is {@see self::deleteCertificateIssuanceConfigAsync()} . + * + * @param DeleteCertificateIssuanceConfigRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function deleteCertificateIssuanceConfig(DeleteCertificateIssuanceConfigRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('DeleteCertificateIssuanceConfig', $request, $callOptions)->wait(); + } + + /** + * Deletes a single CertificateMap. A Certificate Map can't be deleted + * if it contains Certificate Map Entries. Remove all the entries from + * the map before calling this method. + * + * The async variant is {@see self::deleteCertificateMapAsync()} . + * + * @param DeleteCertificateMapRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function deleteCertificateMap(DeleteCertificateMapRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('DeleteCertificateMap', $request, $callOptions)->wait(); + } + + /** + * Deletes a single CertificateMapEntry. + * + * The async variant is {@see self::deleteCertificateMapEntryAsync()} . + * + * @param DeleteCertificateMapEntryRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function deleteCertificateMapEntry(DeleteCertificateMapEntryRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('DeleteCertificateMapEntry', $request, $callOptions)->wait(); + } + + /** + * Deletes a single DnsAuthorization. + * + * The async variant is {@see self::deleteDnsAuthorizationAsync()} . + * + * @param DeleteDnsAuthorizationRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function deleteDnsAuthorization(DeleteDnsAuthorizationRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('DeleteDnsAuthorization', $request, $callOptions)->wait(); + } + + /** + * Gets details of a single Certificate. + * + * The async variant is {@see self::getCertificateAsync()} . + * + * @param GetCertificateRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Certificate + * + * @throws ApiException Thrown if the API call fails. + */ + public function getCertificate(GetCertificateRequest $request, array $callOptions = []): Certificate + { + return $this->startApiCall('GetCertificate', $request, $callOptions)->wait(); + } + + /** + * Gets details of a single CertificateIssuanceConfig. + * + * The async variant is {@see self::getCertificateIssuanceConfigAsync()} . + * + * @param GetCertificateIssuanceConfigRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return CertificateIssuanceConfig + * + * @throws ApiException Thrown if the API call fails. + */ + public function getCertificateIssuanceConfig(GetCertificateIssuanceConfigRequest $request, array $callOptions = []): CertificateIssuanceConfig + { + return $this->startApiCall('GetCertificateIssuanceConfig', $request, $callOptions)->wait(); + } + + /** + * Gets details of a single CertificateMap. + * + * The async variant is {@see self::getCertificateMapAsync()} . + * + * @param GetCertificateMapRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return CertificateMap + * + * @throws ApiException Thrown if the API call fails. + */ + public function getCertificateMap(GetCertificateMapRequest $request, array $callOptions = []): CertificateMap + { + return $this->startApiCall('GetCertificateMap', $request, $callOptions)->wait(); + } + + /** + * Gets details of a single CertificateMapEntry. + * + * The async variant is {@see self::getCertificateMapEntryAsync()} . + * + * @param GetCertificateMapEntryRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return CertificateMapEntry + * + * @throws ApiException Thrown if the API call fails. + */ + public function getCertificateMapEntry(GetCertificateMapEntryRequest $request, array $callOptions = []): CertificateMapEntry + { + return $this->startApiCall('GetCertificateMapEntry', $request, $callOptions)->wait(); + } + + /** + * Gets details of a single DnsAuthorization. + * + * The async variant is {@see self::getDnsAuthorizationAsync()} . + * + * @param GetDnsAuthorizationRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return DnsAuthorization + * + * @throws ApiException Thrown if the API call fails. + */ + public function getDnsAuthorization(GetDnsAuthorizationRequest $request, array $callOptions = []): DnsAuthorization + { + return $this->startApiCall('GetDnsAuthorization', $request, $callOptions)->wait(); + } + + /** + * Lists CertificateIssuanceConfigs in a given project and location. + * + * The async variant is {@see self::listCertificateIssuanceConfigsAsync()} . + * + * @param ListCertificateIssuanceConfigsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listCertificateIssuanceConfigs(ListCertificateIssuanceConfigsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListCertificateIssuanceConfigs', $request, $callOptions); + } + + /** + * Lists CertificateMapEntries in a given project and location. + * + * The async variant is {@see self::listCertificateMapEntriesAsync()} . + * + * @param ListCertificateMapEntriesRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listCertificateMapEntries(ListCertificateMapEntriesRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListCertificateMapEntries', $request, $callOptions); + } + + /** + * Lists CertificateMaps in a given project and location. + * + * The async variant is {@see self::listCertificateMapsAsync()} . + * + * @param ListCertificateMapsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listCertificateMaps(ListCertificateMapsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListCertificateMaps', $request, $callOptions); + } + + /** + * Lists Certificates in a given project and location. + * + * The async variant is {@see self::listCertificatesAsync()} . + * + * @param ListCertificatesRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listCertificates(ListCertificatesRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListCertificates', $request, $callOptions); + } + + /** + * Lists DnsAuthorizations in a given project and location. + * + * The async variant is {@see self::listDnsAuthorizationsAsync()} . + * + * @param ListDnsAuthorizationsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listDnsAuthorizations(ListDnsAuthorizationsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListDnsAuthorizations', $request, $callOptions); + } + + /** + * Updates a Certificate. + * + * The async variant is {@see self::updateCertificateAsync()} . + * + * @param UpdateCertificateRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function updateCertificate(UpdateCertificateRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('UpdateCertificate', $request, $callOptions)->wait(); + } + + /** + * Updates a CertificateMap. + * + * The async variant is {@see self::updateCertificateMapAsync()} . + * + * @param UpdateCertificateMapRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function updateCertificateMap(UpdateCertificateMapRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('UpdateCertificateMap', $request, $callOptions)->wait(); + } + + /** + * Updates a CertificateMapEntry. + * + * The async variant is {@see self::updateCertificateMapEntryAsync()} . + * + * @param UpdateCertificateMapEntryRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function updateCertificateMapEntry(UpdateCertificateMapEntryRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('UpdateCertificateMapEntry', $request, $callOptions)->wait(); + } + + /** + * Updates a DnsAuthorization. + * + * The async variant is {@see self::updateDnsAuthorizationAsync()} . + * + * @param UpdateDnsAuthorizationRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function updateDnsAuthorization(UpdateDnsAuthorizationRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('UpdateDnsAuthorization', $request, $callOptions)->wait(); + } + + /** + * Gets information about a location. + * + * The async variant is {@see self::getLocationAsync()} . + * + * @param GetLocationRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Location + * + * @throws ApiException Thrown if the API call fails. + */ + public function getLocation(GetLocationRequest $request, array $callOptions = []): Location + { + return $this->startApiCall('GetLocation', $request, $callOptions)->wait(); + } + + /** + * Lists information about the supported locations for this service. + * + * The async variant is {@see self::listLocationsAsync()} . + * + * @param ListLocationsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listLocations(ListLocationsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListLocations', $request, $callOptions); + } +} diff --git a/CertificateManager/src/V1/Client/CertificateManagerClient.php b/CertificateManager/src/V1/Client/CertificateManagerClient.php new file mode 100644 index 000000000000..69f89dc8a4e8 --- /dev/null +++ b/CertificateManager/src/V1/Client/CertificateManagerClient.php @@ -0,0 +1,40 @@ +setParent($parent) + ->setCertificateIssuanceConfig($certificateIssuanceConfig) + ->setCertificateIssuanceConfigId($certificateIssuanceConfigId); + } + /** * Constructor. * diff --git a/CertificateManager/src/V1/CreateCertificateMapEntryRequest.php b/CertificateManager/src/V1/CreateCertificateMapEntryRequest.php index 5ab44b777851..41e0cbb5fa7f 100644 --- a/CertificateManager/src/V1/CreateCertificateMapEntryRequest.php +++ b/CertificateManager/src/V1/CreateCertificateMapEntryRequest.php @@ -35,6 +35,25 @@ class CreateCertificateMapEntryRequest extends \Google\Protobuf\Internal\Message */ private $certificate_map_entry = null; + /** + * @param string $parent Required. The parent resource of the certificate map entry. Must be in the + * format `projects/*/locations/*/certificateMaps/*`. Please see + * {@see CertificateManagerClient::certificateMapName()} for help formatting this field. + * @param \Google\Cloud\CertificateManager\V1\CertificateMapEntry $certificateMapEntry Required. A definition of the certificate map entry to create. + * @param string $certificateMapEntryId Required. A user-provided name of the certificate map entry. + * + * @return \Google\Cloud\CertificateManager\V1\CreateCertificateMapEntryRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\CertificateManager\V1\CertificateMapEntry $certificateMapEntry, string $certificateMapEntryId): self + { + return (new self()) + ->setParent($parent) + ->setCertificateMapEntry($certificateMapEntry) + ->setCertificateMapEntryId($certificateMapEntryId); + } + /** * Constructor. * diff --git a/CertificateManager/src/V1/CreateCertificateMapRequest.php b/CertificateManager/src/V1/CreateCertificateMapRequest.php index 7ef0d49f64c5..ae5fce3267b7 100644 --- a/CertificateManager/src/V1/CreateCertificateMapRequest.php +++ b/CertificateManager/src/V1/CreateCertificateMapRequest.php @@ -35,6 +35,25 @@ class CreateCertificateMapRequest extends \Google\Protobuf\Internal\Message */ private $certificate_map = null; + /** + * @param string $parent Required. The parent resource of the certificate map. Must be in the format + * `projects/*/locations/*`. Please see + * {@see CertificateManagerClient::locationName()} for help formatting this field. + * @param \Google\Cloud\CertificateManager\V1\CertificateMap $certificateMap Required. A definition of the certificate map to create. + * @param string $certificateMapId Required. A user-provided name of the certificate map. + * + * @return \Google\Cloud\CertificateManager\V1\CreateCertificateMapRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\CertificateManager\V1\CertificateMap $certificateMap, string $certificateMapId): self + { + return (new self()) + ->setParent($parent) + ->setCertificateMap($certificateMap) + ->setCertificateMapId($certificateMapId); + } + /** * Constructor. * diff --git a/CertificateManager/src/V1/CreateCertificateRequest.php b/CertificateManager/src/V1/CreateCertificateRequest.php index cb0fb956853a..d13ee9f5a5d3 100644 --- a/CertificateManager/src/V1/CreateCertificateRequest.php +++ b/CertificateManager/src/V1/CreateCertificateRequest.php @@ -35,6 +35,25 @@ class CreateCertificateRequest extends \Google\Protobuf\Internal\Message */ private $certificate = null; + /** + * @param string $parent Required. The parent resource of the certificate. Must be in the format + * `projects/*/locations/*`. Please see + * {@see CertificateManagerClient::locationName()} for help formatting this field. + * @param \Google\Cloud\CertificateManager\V1\Certificate $certificate Required. A definition of the certificate to create. + * @param string $certificateId Required. A user-provided name of the certificate. + * + * @return \Google\Cloud\CertificateManager\V1\CreateCertificateRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\CertificateManager\V1\Certificate $certificate, string $certificateId): self + { + return (new self()) + ->setParent($parent) + ->setCertificate($certificate) + ->setCertificateId($certificateId); + } + /** * Constructor. * diff --git a/CertificateManager/src/V1/CreateDnsAuthorizationRequest.php b/CertificateManager/src/V1/CreateDnsAuthorizationRequest.php index 957869a7181f..938be19117ed 100644 --- a/CertificateManager/src/V1/CreateDnsAuthorizationRequest.php +++ b/CertificateManager/src/V1/CreateDnsAuthorizationRequest.php @@ -35,6 +35,25 @@ class CreateDnsAuthorizationRequest extends \Google\Protobuf\Internal\Message */ private $dns_authorization = null; + /** + * @param string $parent Required. The parent resource of the dns authorization. Must be in the + * format `projects/*/locations/*`. Please see + * {@see CertificateManagerClient::locationName()} for help formatting this field. + * @param \Google\Cloud\CertificateManager\V1\DnsAuthorization $dnsAuthorization Required. A definition of the dns authorization to create. + * @param string $dnsAuthorizationId Required. A user-provided name of the dns authorization. + * + * @return \Google\Cloud\CertificateManager\V1\CreateDnsAuthorizationRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\CertificateManager\V1\DnsAuthorization $dnsAuthorization, string $dnsAuthorizationId): self + { + return (new self()) + ->setParent($parent) + ->setDnsAuthorization($dnsAuthorization) + ->setDnsAuthorizationId($dnsAuthorizationId); + } + /** * Constructor. * diff --git a/CertificateManager/src/V1/DeleteCertificateIssuanceConfigRequest.php b/CertificateManager/src/V1/DeleteCertificateIssuanceConfigRequest.php index 84ea17d45188..ab71b300ca0b 100644 --- a/CertificateManager/src/V1/DeleteCertificateIssuanceConfigRequest.php +++ b/CertificateManager/src/V1/DeleteCertificateIssuanceConfigRequest.php @@ -23,6 +23,21 @@ class DeleteCertificateIssuanceConfigRequest extends \Google\Protobuf\Internal\M */ private $name = ''; + /** + * @param string $name Required. A name of the certificate issuance config to delete. Must be in + * the format `projects/*/locations/*/certificateIssuanceConfigs/*`. Please see + * {@see CertificateManagerClient::certificateIssuanceConfigName()} for help formatting this field. + * + * @return \Google\Cloud\CertificateManager\V1\DeleteCertificateIssuanceConfigRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/CertificateManager/src/V1/DeleteCertificateMapEntryRequest.php b/CertificateManager/src/V1/DeleteCertificateMapEntryRequest.php index 78e322841f5f..9c86fa3e3a5e 100644 --- a/CertificateManager/src/V1/DeleteCertificateMapEntryRequest.php +++ b/CertificateManager/src/V1/DeleteCertificateMapEntryRequest.php @@ -23,6 +23,21 @@ class DeleteCertificateMapEntryRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. A name of the certificate map entry to delete. Must be in the + * format `projects/*/locations/*/certificateMaps/*/certificateMapEntries/*`. Please see + * {@see CertificateManagerClient::certificateMapEntryName()} for help formatting this field. + * + * @return \Google\Cloud\CertificateManager\V1\DeleteCertificateMapEntryRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/CertificateManager/src/V1/DeleteCertificateMapRequest.php b/CertificateManager/src/V1/DeleteCertificateMapRequest.php index 1da24c497f36..3223041cd941 100644 --- a/CertificateManager/src/V1/DeleteCertificateMapRequest.php +++ b/CertificateManager/src/V1/DeleteCertificateMapRequest.php @@ -23,6 +23,21 @@ class DeleteCertificateMapRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. A name of the certificate map to delete. Must be in the format + * `projects/*/locations/*/certificateMaps/*`. Please see + * {@see CertificateManagerClient::certificateMapName()} for help formatting this field. + * + * @return \Google\Cloud\CertificateManager\V1\DeleteCertificateMapRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/CertificateManager/src/V1/DeleteCertificateRequest.php b/CertificateManager/src/V1/DeleteCertificateRequest.php index e6ddc0b1c692..7d3f8143b5e5 100644 --- a/CertificateManager/src/V1/DeleteCertificateRequest.php +++ b/CertificateManager/src/V1/DeleteCertificateRequest.php @@ -23,6 +23,21 @@ class DeleteCertificateRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. A name of the certificate to delete. Must be in the format + * `projects/*/locations/*/certificates/*`. Please see + * {@see CertificateManagerClient::certificateName()} for help formatting this field. + * + * @return \Google\Cloud\CertificateManager\V1\DeleteCertificateRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/CertificateManager/src/V1/DeleteDnsAuthorizationRequest.php b/CertificateManager/src/V1/DeleteDnsAuthorizationRequest.php index e39f73565874..e4779ba28807 100644 --- a/CertificateManager/src/V1/DeleteDnsAuthorizationRequest.php +++ b/CertificateManager/src/V1/DeleteDnsAuthorizationRequest.php @@ -23,6 +23,21 @@ class DeleteDnsAuthorizationRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. A name of the dns authorization to delete. Must be in the format + * `projects/*/locations/*/dnsAuthorizations/*`. Please see + * {@see CertificateManagerClient::dnsAuthorizationName()} for help formatting this field. + * + * @return \Google\Cloud\CertificateManager\V1\DeleteDnsAuthorizationRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/CertificateManager/src/V1/GetCertificateIssuanceConfigRequest.php b/CertificateManager/src/V1/GetCertificateIssuanceConfigRequest.php index a77d3b73ab95..1261e71cbea7 100644 --- a/CertificateManager/src/V1/GetCertificateIssuanceConfigRequest.php +++ b/CertificateManager/src/V1/GetCertificateIssuanceConfigRequest.php @@ -23,6 +23,21 @@ class GetCertificateIssuanceConfigRequest extends \Google\Protobuf\Internal\Mess */ private $name = ''; + /** + * @param string $name Required. A name of the certificate issuance config to describe. Must be in + * the format `projects/*/locations/*/certificateIssuanceConfigs/*`. Please see + * {@see CertificateManagerClient::certificateIssuanceConfigName()} for help formatting this field. + * + * @return \Google\Cloud\CertificateManager\V1\GetCertificateIssuanceConfigRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/CertificateManager/src/V1/GetCertificateMapEntryRequest.php b/CertificateManager/src/V1/GetCertificateMapEntryRequest.php index ddfcc4f57c7c..9ed5855bede2 100644 --- a/CertificateManager/src/V1/GetCertificateMapEntryRequest.php +++ b/CertificateManager/src/V1/GetCertificateMapEntryRequest.php @@ -23,6 +23,21 @@ class GetCertificateMapEntryRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. A name of the certificate map entry to describe. Must be in the + * format `projects/*/locations/*/certificateMaps/*/certificateMapEntries/*`. Please see + * {@see CertificateManagerClient::certificateMapEntryName()} for help formatting this field. + * + * @return \Google\Cloud\CertificateManager\V1\GetCertificateMapEntryRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/CertificateManager/src/V1/GetCertificateMapRequest.php b/CertificateManager/src/V1/GetCertificateMapRequest.php index ecdcebac8622..d6b285b40dd2 100644 --- a/CertificateManager/src/V1/GetCertificateMapRequest.php +++ b/CertificateManager/src/V1/GetCertificateMapRequest.php @@ -23,6 +23,21 @@ class GetCertificateMapRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. A name of the certificate map to describe. Must be in the format + * `projects/*/locations/*/certificateMaps/*`. Please see + * {@see CertificateManagerClient::certificateMapName()} for help formatting this field. + * + * @return \Google\Cloud\CertificateManager\V1\GetCertificateMapRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/CertificateManager/src/V1/GetCertificateRequest.php b/CertificateManager/src/V1/GetCertificateRequest.php index fb6c1fa811c6..666b07566966 100644 --- a/CertificateManager/src/V1/GetCertificateRequest.php +++ b/CertificateManager/src/V1/GetCertificateRequest.php @@ -23,6 +23,21 @@ class GetCertificateRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. A name of the certificate to describe. Must be in the format + * `projects/*/locations/*/certificates/*`. Please see + * {@see CertificateManagerClient::certificateName()} for help formatting this field. + * + * @return \Google\Cloud\CertificateManager\V1\GetCertificateRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/CertificateManager/src/V1/GetDnsAuthorizationRequest.php b/CertificateManager/src/V1/GetDnsAuthorizationRequest.php index ce136e92fb9e..ce2f0291c6a2 100644 --- a/CertificateManager/src/V1/GetDnsAuthorizationRequest.php +++ b/CertificateManager/src/V1/GetDnsAuthorizationRequest.php @@ -23,6 +23,21 @@ class GetDnsAuthorizationRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. A name of the dns authorization to describe. Must be in the + * format `projects/*/locations/*/dnsAuthorizations/*`. Please see + * {@see CertificateManagerClient::dnsAuthorizationName()} for help formatting this field. + * + * @return \Google\Cloud\CertificateManager\V1\GetDnsAuthorizationRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/CertificateManager/src/V1/ListCertificateIssuanceConfigsRequest.php b/CertificateManager/src/V1/ListCertificateIssuanceConfigsRequest.php index 652eebdb5327..b29b743373ce 100644 --- a/CertificateManager/src/V1/ListCertificateIssuanceConfigsRequest.php +++ b/CertificateManager/src/V1/ListCertificateIssuanceConfigsRequest.php @@ -52,6 +52,21 @@ class ListCertificateIssuanceConfigsRequest extends \Google\Protobuf\Internal\Me */ private $order_by = ''; + /** + * @param string $parent Required. The project and location from which the certificate should be + * listed, specified in the format `projects/*/locations/*`. Please see + * {@see CertificateManagerClient::locationName()} for help formatting this field. + * + * @return \Google\Cloud\CertificateManager\V1\ListCertificateIssuanceConfigsRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/CertificateManager/src/V1/ListCertificateMapEntriesRequest.php b/CertificateManager/src/V1/ListCertificateMapEntriesRequest.php index 57e00544fd4a..957ed7e760d6 100644 --- a/CertificateManager/src/V1/ListCertificateMapEntriesRequest.php +++ b/CertificateManager/src/V1/ListCertificateMapEntriesRequest.php @@ -56,6 +56,22 @@ class ListCertificateMapEntriesRequest extends \Google\Protobuf\Internal\Message */ private $order_by = ''; + /** + * @param string $parent Required. The project, location and certificate map from which the + * certificate map entries should be listed, specified in the format + * `projects/*/locations/*/certificateMaps/*`. Please see + * {@see CertificateManagerClient::certificateMapName()} for help formatting this field. + * + * @return \Google\Cloud\CertificateManager\V1\ListCertificateMapEntriesRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/CertificateManager/src/V1/ListCertificateMapsRequest.php b/CertificateManager/src/V1/ListCertificateMapsRequest.php index b8ed892a7b71..b79b44a294bf 100644 --- a/CertificateManager/src/V1/ListCertificateMapsRequest.php +++ b/CertificateManager/src/V1/ListCertificateMapsRequest.php @@ -51,6 +51,21 @@ class ListCertificateMapsRequest extends \Google\Protobuf\Internal\Message */ private $order_by = ''; + /** + * @param string $parent Required. The project and location from which the certificate maps should + * be listed, specified in the format `projects/*/locations/*`. Please see + * {@see CertificateManagerClient::locationName()} for help formatting this field. + * + * @return \Google\Cloud\CertificateManager\V1\ListCertificateMapsRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/CertificateManager/src/V1/ListCertificatesRequest.php b/CertificateManager/src/V1/ListCertificatesRequest.php index 9194c57628fa..8f7d2f6ca494 100644 --- a/CertificateManager/src/V1/ListCertificatesRequest.php +++ b/CertificateManager/src/V1/ListCertificatesRequest.php @@ -51,6 +51,21 @@ class ListCertificatesRequest extends \Google\Protobuf\Internal\Message */ private $order_by = ''; + /** + * @param string $parent Required. The project and location from which the certificate should be + * listed, specified in the format `projects/*/locations/*`. Please see + * {@see CertificateManagerClient::locationName()} for help formatting this field. + * + * @return \Google\Cloud\CertificateManager\V1\ListCertificatesRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/CertificateManager/src/V1/ListDnsAuthorizationsRequest.php b/CertificateManager/src/V1/ListDnsAuthorizationsRequest.php index 45b1b68c3315..b0fba8c1af48 100644 --- a/CertificateManager/src/V1/ListDnsAuthorizationsRequest.php +++ b/CertificateManager/src/V1/ListDnsAuthorizationsRequest.php @@ -51,6 +51,21 @@ class ListDnsAuthorizationsRequest extends \Google\Protobuf\Internal\Message */ private $order_by = ''; + /** + * @param string $parent Required. The project and location from which the dns authorizations should + * be listed, specified in the format `projects/*/locations/*`. Please see + * {@see CertificateManagerClient::locationName()} for help formatting this field. + * + * @return \Google\Cloud\CertificateManager\V1\ListDnsAuthorizationsRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/CertificateManager/src/V1/UpdateCertificateMapEntryRequest.php b/CertificateManager/src/V1/UpdateCertificateMapEntryRequest.php index 2e89b3b2ea2f..29b69c45fe7a 100644 --- a/CertificateManager/src/V1/UpdateCertificateMapEntryRequest.php +++ b/CertificateManager/src/V1/UpdateCertificateMapEntryRequest.php @@ -30,6 +30,23 @@ class UpdateCertificateMapEntryRequest extends \Google\Protobuf\Internal\Message */ private $update_mask = null; + /** + * @param \Google\Cloud\CertificateManager\V1\CertificateMapEntry $certificateMapEntry Required. A definition of the certificate map entry to create map entry. + * @param \Google\Protobuf\FieldMask $updateMask Required. The update mask applies to the resource. For the `FieldMask` + * definition, see + * https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#fieldmask. + * + * @return \Google\Cloud\CertificateManager\V1\UpdateCertificateMapEntryRequest + * + * @experimental + */ + public static function build(\Google\Cloud\CertificateManager\V1\CertificateMapEntry $certificateMapEntry, \Google\Protobuf\FieldMask $updateMask): self + { + return (new self()) + ->setCertificateMapEntry($certificateMapEntry) + ->setUpdateMask($updateMask); + } + /** * Constructor. * diff --git a/CertificateManager/src/V1/UpdateCertificateMapRequest.php b/CertificateManager/src/V1/UpdateCertificateMapRequest.php index 8b938c701306..f5c894c88324 100644 --- a/CertificateManager/src/V1/UpdateCertificateMapRequest.php +++ b/CertificateManager/src/V1/UpdateCertificateMapRequest.php @@ -30,6 +30,23 @@ class UpdateCertificateMapRequest extends \Google\Protobuf\Internal\Message */ private $update_mask = null; + /** + * @param \Google\Cloud\CertificateManager\V1\CertificateMap $certificateMap Required. A definition of the certificate map to update. + * @param \Google\Protobuf\FieldMask $updateMask Required. The update mask applies to the resource. For the `FieldMask` + * definition, see + * https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#fieldmask. + * + * @return \Google\Cloud\CertificateManager\V1\UpdateCertificateMapRequest + * + * @experimental + */ + public static function build(\Google\Cloud\CertificateManager\V1\CertificateMap $certificateMap, \Google\Protobuf\FieldMask $updateMask): self + { + return (new self()) + ->setCertificateMap($certificateMap) + ->setUpdateMask($updateMask); + } + /** * Constructor. * diff --git a/CertificateManager/src/V1/UpdateCertificateRequest.php b/CertificateManager/src/V1/UpdateCertificateRequest.php index 5b2e0d0bba85..6e6a9043a1ce 100644 --- a/CertificateManager/src/V1/UpdateCertificateRequest.php +++ b/CertificateManager/src/V1/UpdateCertificateRequest.php @@ -30,6 +30,23 @@ class UpdateCertificateRequest extends \Google\Protobuf\Internal\Message */ private $update_mask = null; + /** + * @param \Google\Cloud\CertificateManager\V1\Certificate $certificate Required. A definition of the certificate to update. + * @param \Google\Protobuf\FieldMask $updateMask Required. The update mask applies to the resource. For the `FieldMask` + * definition, see + * https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#fieldmask. + * + * @return \Google\Cloud\CertificateManager\V1\UpdateCertificateRequest + * + * @experimental + */ + public static function build(\Google\Cloud\CertificateManager\V1\Certificate $certificate, \Google\Protobuf\FieldMask $updateMask): self + { + return (new self()) + ->setCertificate($certificate) + ->setUpdateMask($updateMask); + } + /** * Constructor. * diff --git a/CertificateManager/src/V1/UpdateDnsAuthorizationRequest.php b/CertificateManager/src/V1/UpdateDnsAuthorizationRequest.php index 0515eaaf653c..6308c2564f12 100644 --- a/CertificateManager/src/V1/UpdateDnsAuthorizationRequest.php +++ b/CertificateManager/src/V1/UpdateDnsAuthorizationRequest.php @@ -30,6 +30,23 @@ class UpdateDnsAuthorizationRequest extends \Google\Protobuf\Internal\Message */ private $update_mask = null; + /** + * @param \Google\Cloud\CertificateManager\V1\DnsAuthorization $dnsAuthorization Required. A definition of the dns authorization to update. + * @param \Google\Protobuf\FieldMask $updateMask Required. The update mask applies to the resource. For the `FieldMask` + * definition, see + * https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#fieldmask. + * + * @return \Google\Cloud\CertificateManager\V1\UpdateDnsAuthorizationRequest + * + * @experimental + */ + public static function build(\Google\Cloud\CertificateManager\V1\DnsAuthorization $dnsAuthorization, \Google\Protobuf\FieldMask $updateMask): self + { + return (new self()) + ->setDnsAuthorization($dnsAuthorization) + ->setUpdateMask($updateMask); + } + /** * Constructor. * diff --git a/CertificateManager/src/V1/resources/certificate_manager_descriptor_config.php b/CertificateManager/src/V1/resources/certificate_manager_descriptor_config.php index db80ff631192..ae4523289cd3 100644 --- a/CertificateManager/src/V1/resources/certificate_manager_descriptor_config.php +++ b/CertificateManager/src/V1/resources/certificate_manager_descriptor_config.php @@ -12,6 +12,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'CreateCertificateIssuanceConfig' => [ 'longRunning' => [ @@ -22,6 +31,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'CreateCertificateMap' => [ 'longRunning' => [ @@ -32,6 +50,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'CreateCertificateMapEntry' => [ 'longRunning' => [ @@ -42,6 +69,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'CreateDnsAuthorization' => [ 'longRunning' => [ @@ -52,6 +88,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'DeleteCertificate' => [ 'longRunning' => [ @@ -62,6 +107,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'DeleteCertificateIssuanceConfig' => [ 'longRunning' => [ @@ -72,6 +126,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'DeleteCertificateMap' => [ 'longRunning' => [ @@ -82,6 +145,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'DeleteCertificateMapEntry' => [ 'longRunning' => [ @@ -92,6 +164,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'DeleteDnsAuthorization' => [ 'longRunning' => [ @@ -102,6 +183,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'UpdateCertificate' => [ 'longRunning' => [ @@ -112,6 +202,16 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'certificate.name', + 'fieldAccessors' => [ + 'getCertificate', + 'getName', + ], + ], + ], ], 'UpdateCertificateMap' => [ 'longRunning' => [ @@ -122,6 +222,16 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'certificate_map.name', + 'fieldAccessors' => [ + 'getCertificateMap', + 'getName', + ], + ], + ], ], 'UpdateCertificateMapEntry' => [ 'longRunning' => [ @@ -132,6 +242,16 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'certificate_map_entry.name', + 'fieldAccessors' => [ + 'getCertificateMapEntry', + 'getName', + ], + ], + ], ], 'UpdateDnsAuthorization' => [ 'longRunning' => [ @@ -142,6 +262,76 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'dns_authorization.name', + 'fieldAccessors' => [ + 'getDnsAuthorization', + 'getName', + ], + ], + ], + ], + 'GetCertificate' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\CertificateManager\V1\Certificate', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetCertificateIssuanceConfig' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\CertificateManager\V1\CertificateIssuanceConfig', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetCertificateMap' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\CertificateManager\V1\CertificateMap', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetCertificateMapEntry' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\CertificateManager\V1\CertificateMapEntry', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetDnsAuthorization' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\CertificateManager\V1\DnsAuthorization', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'ListCertificateIssuanceConfigs' => [ 'pageStreaming' => [ @@ -152,6 +342,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getCertificateIssuanceConfigs', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\CertificateManager\V1\ListCertificateIssuanceConfigsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ListCertificateMapEntries' => [ 'pageStreaming' => [ @@ -162,6 +362,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getCertificateMapEntries', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\CertificateManager\V1\ListCertificateMapEntriesResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ListCertificateMaps' => [ 'pageStreaming' => [ @@ -172,6 +382,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getCertificateMaps', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\CertificateManager\V1\ListCertificateMapsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ListCertificates' => [ 'pageStreaming' => [ @@ -182,6 +402,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getCertificates', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\CertificateManager\V1\ListCertificatesResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ListDnsAuthorizations' => [ 'pageStreaming' => [ @@ -192,8 +422,28 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getDnsAuthorizations', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\CertificateManager\V1\ListDnsAuthorizationsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'GetLocation' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Location\Location', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], 'interfaceOverride' => 'google.cloud.location.Locations', ], 'ListLocations' => [ @@ -205,8 +455,27 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getLocations', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\Location\ListLocationsResponse', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], 'interfaceOverride' => 'google.cloud.location.Locations', ], + 'templateMap' => [ + 'caPool' => 'projects/{project}/locations/{location}/caPools/{ca_pool}', + 'certificate' => 'projects/{project}/locations/{location}/certificates/{certificate}', + 'certificateIssuanceConfig' => 'projects/{project}/locations/{location}/certificateIssuanceConfigs/{certificate_issuance_config}', + 'certificateMap' => 'projects/{project}/locations/{location}/certificateMaps/{certificate_map}', + 'certificateMapEntry' => 'projects/{project}/locations/{location}/certificateMaps/{certificate_map}/certificateMapEntries/{certificate_map_entry}', + 'dnsAuthorization' => 'projects/{project}/locations/{location}/dnsAuthorizations/{dns_authorization}', + 'location' => 'projects/{project}/locations/{location}', + ], ], ], ]; diff --git a/CertificateManager/tests/Unit/V1/Client/CertificateManagerClientTest.php b/CertificateManager/tests/Unit/V1/Client/CertificateManagerClientTest.php new file mode 100644 index 000000000000..3c4115a7ea85 --- /dev/null +++ b/CertificateManager/tests/Unit/V1/Client/CertificateManagerClientTest.php @@ -0,0 +1,2859 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return CertificateManagerClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new CertificateManagerClient($options); + } + + /** @test */ + public function createCertificateTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/createCertificateTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $description = 'description-1724546052'; + $pemCertificate = 'pemCertificate1234463984'; + $expectedResponse = new Certificate(); + $expectedResponse->setName($name); + $expectedResponse->setDescription($description); + $expectedResponse->setPemCertificate($pemCertificate); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createCertificateTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $certificateId = 'certificateId1494430915'; + $certificate = new Certificate(); + $request = (new CreateCertificateRequest()) + ->setParent($formattedParent) + ->setCertificateId($certificateId) + ->setCertificate($certificate); + $response = $gapicClient->createCertificate($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.certificatemanager.v1.CertificateManager/CreateCertificate', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getCertificateId(); + $this->assertProtobufEquals($certificateId, $actualValue); + $actualValue = $actualApiRequestObject->getCertificate(); + $this->assertProtobufEquals($certificate, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createCertificateTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function createCertificateExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/createCertificateTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $certificateId = 'certificateId1494430915'; + $certificate = new Certificate(); + $request = (new CreateCertificateRequest()) + ->setParent($formattedParent) + ->setCertificateId($certificateId) + ->setCertificate($certificate); + $response = $gapicClient->createCertificate($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createCertificateTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function createCertificateIssuanceConfigTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/createCertificateIssuanceConfigTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $description = 'description-1724546052'; + $rotationWindowPercentage = 873917384; + $expectedResponse = new CertificateIssuanceConfig(); + $expectedResponse->setName($name); + $expectedResponse->setDescription($description); + $expectedResponse->setRotationWindowPercentage($rotationWindowPercentage); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createCertificateIssuanceConfigTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $certificateIssuanceConfigId = 'certificateIssuanceConfigId635650044'; + $certificateIssuanceConfig = new CertificateIssuanceConfig(); + $certificateIssuanceConfigCertificateAuthorityConfig = new CertificateAuthorityConfig(); + $certificateIssuanceConfig->setCertificateAuthorityConfig($certificateIssuanceConfigCertificateAuthorityConfig); + $certificateIssuanceConfigLifetime = new Duration(); + $certificateIssuanceConfig->setLifetime($certificateIssuanceConfigLifetime); + $certificateIssuanceConfigRotationWindowPercentage = 1410864292; + $certificateIssuanceConfig->setRotationWindowPercentage($certificateIssuanceConfigRotationWindowPercentage); + $certificateIssuanceConfigKeyAlgorithm = KeyAlgorithm::KEY_ALGORITHM_UNSPECIFIED; + $certificateIssuanceConfig->setKeyAlgorithm($certificateIssuanceConfigKeyAlgorithm); + $request = (new CreateCertificateIssuanceConfigRequest()) + ->setParent($formattedParent) + ->setCertificateIssuanceConfigId($certificateIssuanceConfigId) + ->setCertificateIssuanceConfig($certificateIssuanceConfig); + $response = $gapicClient->createCertificateIssuanceConfig($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.certificatemanager.v1.CertificateManager/CreateCertificateIssuanceConfig', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getCertificateIssuanceConfigId(); + $this->assertProtobufEquals($certificateIssuanceConfigId, $actualValue); + $actualValue = $actualApiRequestObject->getCertificateIssuanceConfig(); + $this->assertProtobufEquals($certificateIssuanceConfig, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createCertificateIssuanceConfigTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function createCertificateIssuanceConfigExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/createCertificateIssuanceConfigTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $certificateIssuanceConfigId = 'certificateIssuanceConfigId635650044'; + $certificateIssuanceConfig = new CertificateIssuanceConfig(); + $certificateIssuanceConfigCertificateAuthorityConfig = new CertificateAuthorityConfig(); + $certificateIssuanceConfig->setCertificateAuthorityConfig($certificateIssuanceConfigCertificateAuthorityConfig); + $certificateIssuanceConfigLifetime = new Duration(); + $certificateIssuanceConfig->setLifetime($certificateIssuanceConfigLifetime); + $certificateIssuanceConfigRotationWindowPercentage = 1410864292; + $certificateIssuanceConfig->setRotationWindowPercentage($certificateIssuanceConfigRotationWindowPercentage); + $certificateIssuanceConfigKeyAlgorithm = KeyAlgorithm::KEY_ALGORITHM_UNSPECIFIED; + $certificateIssuanceConfig->setKeyAlgorithm($certificateIssuanceConfigKeyAlgorithm); + $request = (new CreateCertificateIssuanceConfigRequest()) + ->setParent($formattedParent) + ->setCertificateIssuanceConfigId($certificateIssuanceConfigId) + ->setCertificateIssuanceConfig($certificateIssuanceConfig); + $response = $gapicClient->createCertificateIssuanceConfig($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createCertificateIssuanceConfigTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function createCertificateMapTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/createCertificateMapTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $description = 'description-1724546052'; + $expectedResponse = new CertificateMap(); + $expectedResponse->setName($name); + $expectedResponse->setDescription($description); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createCertificateMapTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $certificateMapId = 'certificateMapId-2047700346'; + $certificateMap = new CertificateMap(); + $request = (new CreateCertificateMapRequest()) + ->setParent($formattedParent) + ->setCertificateMapId($certificateMapId) + ->setCertificateMap($certificateMap); + $response = $gapicClient->createCertificateMap($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.certificatemanager.v1.CertificateManager/CreateCertificateMap', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getCertificateMapId(); + $this->assertProtobufEquals($certificateMapId, $actualValue); + $actualValue = $actualApiRequestObject->getCertificateMap(); + $this->assertProtobufEquals($certificateMap, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createCertificateMapTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function createCertificateMapExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/createCertificateMapTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $certificateMapId = 'certificateMapId-2047700346'; + $certificateMap = new CertificateMap(); + $request = (new CreateCertificateMapRequest()) + ->setParent($formattedParent) + ->setCertificateMapId($certificateMapId) + ->setCertificateMap($certificateMap); + $response = $gapicClient->createCertificateMap($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createCertificateMapTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function createCertificateMapEntryTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/createCertificateMapEntryTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $description = 'description-1724546052'; + $hostname = 'hostname-299803597'; + $expectedResponse = new CertificateMapEntry(); + $expectedResponse->setName($name); + $expectedResponse->setDescription($description); + $expectedResponse->setHostname($hostname); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createCertificateMapEntryTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->certificateMapName('[PROJECT]', '[LOCATION]', '[CERTIFICATE_MAP]'); + $certificateMapEntryId = 'certificateMapEntryId78300467'; + $certificateMapEntry = new CertificateMapEntry(); + $request = (new CreateCertificateMapEntryRequest()) + ->setParent($formattedParent) + ->setCertificateMapEntryId($certificateMapEntryId) + ->setCertificateMapEntry($certificateMapEntry); + $response = $gapicClient->createCertificateMapEntry($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.certificatemanager.v1.CertificateManager/CreateCertificateMapEntry', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getCertificateMapEntryId(); + $this->assertProtobufEquals($certificateMapEntryId, $actualValue); + $actualValue = $actualApiRequestObject->getCertificateMapEntry(); + $this->assertProtobufEquals($certificateMapEntry, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createCertificateMapEntryTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function createCertificateMapEntryExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/createCertificateMapEntryTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->certificateMapName('[PROJECT]', '[LOCATION]', '[CERTIFICATE_MAP]'); + $certificateMapEntryId = 'certificateMapEntryId78300467'; + $certificateMapEntry = new CertificateMapEntry(); + $request = (new CreateCertificateMapEntryRequest()) + ->setParent($formattedParent) + ->setCertificateMapEntryId($certificateMapEntryId) + ->setCertificateMapEntry($certificateMapEntry); + $response = $gapicClient->createCertificateMapEntry($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createCertificateMapEntryTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function createDnsAuthorizationTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/createDnsAuthorizationTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $description = 'description-1724546052'; + $domain = 'domain-1326197564'; + $expectedResponse = new DnsAuthorization(); + $expectedResponse->setName($name); + $expectedResponse->setDescription($description); + $expectedResponse->setDomain($domain); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createDnsAuthorizationTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $dnsAuthorizationId = 'dnsAuthorizationId1795311351'; + $dnsAuthorization = new DnsAuthorization(); + $dnsAuthorizationDomain = 'dnsAuthorizationDomain2013928116'; + $dnsAuthorization->setDomain($dnsAuthorizationDomain); + $request = (new CreateDnsAuthorizationRequest()) + ->setParent($formattedParent) + ->setDnsAuthorizationId($dnsAuthorizationId) + ->setDnsAuthorization($dnsAuthorization); + $response = $gapicClient->createDnsAuthorization($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.certificatemanager.v1.CertificateManager/CreateDnsAuthorization', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getDnsAuthorizationId(); + $this->assertProtobufEquals($dnsAuthorizationId, $actualValue); + $actualValue = $actualApiRequestObject->getDnsAuthorization(); + $this->assertProtobufEquals($dnsAuthorization, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createDnsAuthorizationTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function createDnsAuthorizationExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/createDnsAuthorizationTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $dnsAuthorizationId = 'dnsAuthorizationId1795311351'; + $dnsAuthorization = new DnsAuthorization(); + $dnsAuthorizationDomain = 'dnsAuthorizationDomain2013928116'; + $dnsAuthorization->setDomain($dnsAuthorizationDomain); + $request = (new CreateDnsAuthorizationRequest()) + ->setParent($formattedParent) + ->setDnsAuthorizationId($dnsAuthorizationId) + ->setDnsAuthorization($dnsAuthorization); + $response = $gapicClient->createDnsAuthorization($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createDnsAuthorizationTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function deleteCertificateTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/deleteCertificateTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new GPBEmpty(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/deleteCertificateTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->certificateName('[PROJECT]', '[LOCATION]', '[CERTIFICATE]'); + $request = (new DeleteCertificateRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteCertificate($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.certificatemanager.v1.CertificateManager/DeleteCertificate', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteCertificateTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function deleteCertificateExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/deleteCertificateTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->certificateName('[PROJECT]', '[LOCATION]', '[CERTIFICATE]'); + $request = (new DeleteCertificateRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteCertificate($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteCertificateTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function deleteCertificateIssuanceConfigTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/deleteCertificateIssuanceConfigTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new GPBEmpty(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/deleteCertificateIssuanceConfigTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->certificateIssuanceConfigName('[PROJECT]', '[LOCATION]', '[CERTIFICATE_ISSUANCE_CONFIG]'); + $request = (new DeleteCertificateIssuanceConfigRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteCertificateIssuanceConfig($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.certificatemanager.v1.CertificateManager/DeleteCertificateIssuanceConfig', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteCertificateIssuanceConfigTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function deleteCertificateIssuanceConfigExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/deleteCertificateIssuanceConfigTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->certificateIssuanceConfigName('[PROJECT]', '[LOCATION]', '[CERTIFICATE_ISSUANCE_CONFIG]'); + $request = (new DeleteCertificateIssuanceConfigRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteCertificateIssuanceConfig($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteCertificateIssuanceConfigTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function deleteCertificateMapTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/deleteCertificateMapTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new GPBEmpty(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/deleteCertificateMapTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->certificateMapName('[PROJECT]', '[LOCATION]', '[CERTIFICATE_MAP]'); + $request = (new DeleteCertificateMapRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteCertificateMap($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.certificatemanager.v1.CertificateManager/DeleteCertificateMap', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteCertificateMapTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function deleteCertificateMapExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/deleteCertificateMapTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->certificateMapName('[PROJECT]', '[LOCATION]', '[CERTIFICATE_MAP]'); + $request = (new DeleteCertificateMapRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteCertificateMap($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteCertificateMapTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function deleteCertificateMapEntryTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/deleteCertificateMapEntryTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new GPBEmpty(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/deleteCertificateMapEntryTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->certificateMapEntryName('[PROJECT]', '[LOCATION]', '[CERTIFICATE_MAP]', '[CERTIFICATE_MAP_ENTRY]'); + $request = (new DeleteCertificateMapEntryRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteCertificateMapEntry($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.certificatemanager.v1.CertificateManager/DeleteCertificateMapEntry', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteCertificateMapEntryTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function deleteCertificateMapEntryExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/deleteCertificateMapEntryTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->certificateMapEntryName('[PROJECT]', '[LOCATION]', '[CERTIFICATE_MAP]', '[CERTIFICATE_MAP_ENTRY]'); + $request = (new DeleteCertificateMapEntryRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteCertificateMapEntry($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteCertificateMapEntryTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function deleteDnsAuthorizationTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/deleteDnsAuthorizationTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new GPBEmpty(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/deleteDnsAuthorizationTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->dnsAuthorizationName('[PROJECT]', '[LOCATION]', '[DNS_AUTHORIZATION]'); + $request = (new DeleteDnsAuthorizationRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteDnsAuthorization($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.certificatemanager.v1.CertificateManager/DeleteDnsAuthorization', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteDnsAuthorizationTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function deleteDnsAuthorizationExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/deleteDnsAuthorizationTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->dnsAuthorizationName('[PROJECT]', '[LOCATION]', '[DNS_AUTHORIZATION]'); + $request = (new DeleteDnsAuthorizationRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteDnsAuthorization($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteDnsAuthorizationTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function getCertificateTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $description = 'description-1724546052'; + $pemCertificate = 'pemCertificate1234463984'; + $expectedResponse = new Certificate(); + $expectedResponse->setName($name2); + $expectedResponse->setDescription($description); + $expectedResponse->setPemCertificate($pemCertificate); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->certificateName('[PROJECT]', '[LOCATION]', '[CERTIFICATE]'); + $request = (new GetCertificateRequest()) + ->setName($formattedName); + $response = $gapicClient->getCertificate($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.certificatemanager.v1.CertificateManager/GetCertificate', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getCertificateExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->certificateName('[PROJECT]', '[LOCATION]', '[CERTIFICATE]'); + $request = (new GetCertificateRequest()) + ->setName($formattedName); + try { + $gapicClient->getCertificate($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getCertificateIssuanceConfigTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $description = 'description-1724546052'; + $rotationWindowPercentage = 873917384; + $expectedResponse = new CertificateIssuanceConfig(); + $expectedResponse->setName($name2); + $expectedResponse->setDescription($description); + $expectedResponse->setRotationWindowPercentage($rotationWindowPercentage); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->certificateIssuanceConfigName('[PROJECT]', '[LOCATION]', '[CERTIFICATE_ISSUANCE_CONFIG]'); + $request = (new GetCertificateIssuanceConfigRequest()) + ->setName($formattedName); + $response = $gapicClient->getCertificateIssuanceConfig($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.certificatemanager.v1.CertificateManager/GetCertificateIssuanceConfig', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getCertificateIssuanceConfigExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->certificateIssuanceConfigName('[PROJECT]', '[LOCATION]', '[CERTIFICATE_ISSUANCE_CONFIG]'); + $request = (new GetCertificateIssuanceConfigRequest()) + ->setName($formattedName); + try { + $gapicClient->getCertificateIssuanceConfig($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getCertificateMapTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $description = 'description-1724546052'; + $expectedResponse = new CertificateMap(); + $expectedResponse->setName($name2); + $expectedResponse->setDescription($description); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->certificateMapName('[PROJECT]', '[LOCATION]', '[CERTIFICATE_MAP]'); + $request = (new GetCertificateMapRequest()) + ->setName($formattedName); + $response = $gapicClient->getCertificateMap($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.certificatemanager.v1.CertificateManager/GetCertificateMap', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getCertificateMapExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->certificateMapName('[PROJECT]', '[LOCATION]', '[CERTIFICATE_MAP]'); + $request = (new GetCertificateMapRequest()) + ->setName($formattedName); + try { + $gapicClient->getCertificateMap($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getCertificateMapEntryTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $description = 'description-1724546052'; + $hostname = 'hostname-299803597'; + $expectedResponse = new CertificateMapEntry(); + $expectedResponse->setName($name2); + $expectedResponse->setDescription($description); + $expectedResponse->setHostname($hostname); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->certificateMapEntryName('[PROJECT]', '[LOCATION]', '[CERTIFICATE_MAP]', '[CERTIFICATE_MAP_ENTRY]'); + $request = (new GetCertificateMapEntryRequest()) + ->setName($formattedName); + $response = $gapicClient->getCertificateMapEntry($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.certificatemanager.v1.CertificateManager/GetCertificateMapEntry', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getCertificateMapEntryExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->certificateMapEntryName('[PROJECT]', '[LOCATION]', '[CERTIFICATE_MAP]', '[CERTIFICATE_MAP_ENTRY]'); + $request = (new GetCertificateMapEntryRequest()) + ->setName($formattedName); + try { + $gapicClient->getCertificateMapEntry($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getDnsAuthorizationTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $description = 'description-1724546052'; + $domain = 'domain-1326197564'; + $expectedResponse = new DnsAuthorization(); + $expectedResponse->setName($name2); + $expectedResponse->setDescription($description); + $expectedResponse->setDomain($domain); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->dnsAuthorizationName('[PROJECT]', '[LOCATION]', '[DNS_AUTHORIZATION]'); + $request = (new GetDnsAuthorizationRequest()) + ->setName($formattedName); + $response = $gapicClient->getDnsAuthorization($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.certificatemanager.v1.CertificateManager/GetDnsAuthorization', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getDnsAuthorizationExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->dnsAuthorizationName('[PROJECT]', '[LOCATION]', '[DNS_AUTHORIZATION]'); + $request = (new GetDnsAuthorizationRequest()) + ->setName($formattedName); + try { + $gapicClient->getDnsAuthorization($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listCertificateIssuanceConfigsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $certificateIssuanceConfigsElement = new CertificateIssuanceConfig(); + $certificateIssuanceConfigs = [ + $certificateIssuanceConfigsElement, + ]; + $expectedResponse = new ListCertificateIssuanceConfigsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setCertificateIssuanceConfigs($certificateIssuanceConfigs); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListCertificateIssuanceConfigsRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listCertificateIssuanceConfigs($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getCertificateIssuanceConfigs()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.certificatemanager.v1.CertificateManager/ListCertificateIssuanceConfigs', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listCertificateIssuanceConfigsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListCertificateIssuanceConfigsRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listCertificateIssuanceConfigs($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listCertificateMapEntriesTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $certificateMapEntriesElement = new CertificateMapEntry(); + $certificateMapEntries = [ + $certificateMapEntriesElement, + ]; + $expectedResponse = new ListCertificateMapEntriesResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setCertificateMapEntries($certificateMapEntries); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->certificateMapName('[PROJECT]', '[LOCATION]', '[CERTIFICATE_MAP]'); + $request = (new ListCertificateMapEntriesRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listCertificateMapEntries($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getCertificateMapEntries()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.certificatemanager.v1.CertificateManager/ListCertificateMapEntries', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listCertificateMapEntriesExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->certificateMapName('[PROJECT]', '[LOCATION]', '[CERTIFICATE_MAP]'); + $request = (new ListCertificateMapEntriesRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listCertificateMapEntries($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listCertificateMapsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $certificateMapsElement = new CertificateMap(); + $certificateMaps = [ + $certificateMapsElement, + ]; + $expectedResponse = new ListCertificateMapsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setCertificateMaps($certificateMaps); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListCertificateMapsRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listCertificateMaps($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getCertificateMaps()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.certificatemanager.v1.CertificateManager/ListCertificateMaps', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listCertificateMapsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListCertificateMapsRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listCertificateMaps($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listCertificatesTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $certificatesElement = new Certificate(); + $certificates = [ + $certificatesElement, + ]; + $expectedResponse = new ListCertificatesResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setCertificates($certificates); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListCertificatesRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listCertificates($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getCertificates()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.certificatemanager.v1.CertificateManager/ListCertificates', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listCertificatesExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListCertificatesRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listCertificates($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listDnsAuthorizationsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $dnsAuthorizationsElement = new DnsAuthorization(); + $dnsAuthorizations = [ + $dnsAuthorizationsElement, + ]; + $expectedResponse = new ListDnsAuthorizationsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setDnsAuthorizations($dnsAuthorizations); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListDnsAuthorizationsRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listDnsAuthorizations($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getDnsAuthorizations()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.certificatemanager.v1.CertificateManager/ListDnsAuthorizations', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listDnsAuthorizationsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListDnsAuthorizationsRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listDnsAuthorizations($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function updateCertificateTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/updateCertificateTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $description = 'description-1724546052'; + $pemCertificate = 'pemCertificate1234463984'; + $expectedResponse = new Certificate(); + $expectedResponse->setName($name); + $expectedResponse->setDescription($description); + $expectedResponse->setPemCertificate($pemCertificate); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/updateCertificateTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $certificate = new Certificate(); + $updateMask = new FieldMask(); + $request = (new UpdateCertificateRequest()) + ->setCertificate($certificate) + ->setUpdateMask($updateMask); + $response = $gapicClient->updateCertificate($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.certificatemanager.v1.CertificateManager/UpdateCertificate', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getCertificate(); + $this->assertProtobufEquals($certificate, $actualValue); + $actualValue = $actualApiRequestObject->getUpdateMask(); + $this->assertProtobufEquals($updateMask, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateCertificateTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function updateCertificateExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/updateCertificateTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $certificate = new Certificate(); + $updateMask = new FieldMask(); + $request = (new UpdateCertificateRequest()) + ->setCertificate($certificate) + ->setUpdateMask($updateMask); + $response = $gapicClient->updateCertificate($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateCertificateTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function updateCertificateMapTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/updateCertificateMapTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $description = 'description-1724546052'; + $expectedResponse = new CertificateMap(); + $expectedResponse->setName($name); + $expectedResponse->setDescription($description); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/updateCertificateMapTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $certificateMap = new CertificateMap(); + $updateMask = new FieldMask(); + $request = (new UpdateCertificateMapRequest()) + ->setCertificateMap($certificateMap) + ->setUpdateMask($updateMask); + $response = $gapicClient->updateCertificateMap($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.certificatemanager.v1.CertificateManager/UpdateCertificateMap', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getCertificateMap(); + $this->assertProtobufEquals($certificateMap, $actualValue); + $actualValue = $actualApiRequestObject->getUpdateMask(); + $this->assertProtobufEquals($updateMask, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateCertificateMapTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function updateCertificateMapExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/updateCertificateMapTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $certificateMap = new CertificateMap(); + $updateMask = new FieldMask(); + $request = (new UpdateCertificateMapRequest()) + ->setCertificateMap($certificateMap) + ->setUpdateMask($updateMask); + $response = $gapicClient->updateCertificateMap($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateCertificateMapTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function updateCertificateMapEntryTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/updateCertificateMapEntryTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $description = 'description-1724546052'; + $hostname = 'hostname-299803597'; + $expectedResponse = new CertificateMapEntry(); + $expectedResponse->setName($name); + $expectedResponse->setDescription($description); + $expectedResponse->setHostname($hostname); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/updateCertificateMapEntryTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $certificateMapEntry = new CertificateMapEntry(); + $updateMask = new FieldMask(); + $request = (new UpdateCertificateMapEntryRequest()) + ->setCertificateMapEntry($certificateMapEntry) + ->setUpdateMask($updateMask); + $response = $gapicClient->updateCertificateMapEntry($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.certificatemanager.v1.CertificateManager/UpdateCertificateMapEntry', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getCertificateMapEntry(); + $this->assertProtobufEquals($certificateMapEntry, $actualValue); + $actualValue = $actualApiRequestObject->getUpdateMask(); + $this->assertProtobufEquals($updateMask, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateCertificateMapEntryTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function updateCertificateMapEntryExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/updateCertificateMapEntryTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $certificateMapEntry = new CertificateMapEntry(); + $updateMask = new FieldMask(); + $request = (new UpdateCertificateMapEntryRequest()) + ->setCertificateMapEntry($certificateMapEntry) + ->setUpdateMask($updateMask); + $response = $gapicClient->updateCertificateMapEntry($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateCertificateMapEntryTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function updateDnsAuthorizationTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/updateDnsAuthorizationTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $description = 'description-1724546052'; + $domain = 'domain-1326197564'; + $expectedResponse = new DnsAuthorization(); + $expectedResponse->setName($name); + $expectedResponse->setDescription($description); + $expectedResponse->setDomain($domain); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/updateDnsAuthorizationTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $dnsAuthorization = new DnsAuthorization(); + $dnsAuthorizationDomain = 'dnsAuthorizationDomain2013928116'; + $dnsAuthorization->setDomain($dnsAuthorizationDomain); + $updateMask = new FieldMask(); + $request = (new UpdateDnsAuthorizationRequest()) + ->setDnsAuthorization($dnsAuthorization) + ->setUpdateMask($updateMask); + $response = $gapicClient->updateDnsAuthorization($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.certificatemanager.v1.CertificateManager/UpdateDnsAuthorization', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getDnsAuthorization(); + $this->assertProtobufEquals($dnsAuthorization, $actualValue); + $actualValue = $actualApiRequestObject->getUpdateMask(); + $this->assertProtobufEquals($updateMask, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateDnsAuthorizationTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function updateDnsAuthorizationExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/updateDnsAuthorizationTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $dnsAuthorization = new DnsAuthorization(); + $dnsAuthorizationDomain = 'dnsAuthorizationDomain2013928116'; + $dnsAuthorization->setDomain($dnsAuthorizationDomain); + $updateMask = new FieldMask(); + $request = (new UpdateDnsAuthorizationRequest()) + ->setDnsAuthorization($dnsAuthorization) + ->setUpdateMask($updateMask); + $response = $gapicClient->updateDnsAuthorization($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateDnsAuthorizationTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function getLocationTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $locationId = 'locationId552319461'; + $displayName = 'displayName1615086568'; + $expectedResponse = new Location(); + $expectedResponse->setName($name2); + $expectedResponse->setLocationId($locationId); + $expectedResponse->setDisplayName($displayName); + $transport->addResponse($expectedResponse); + $request = new GetLocationRequest(); + $response = $gapicClient->getLocation($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.location.Locations/GetLocation', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getLocationExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + $request = new GetLocationRequest(); + try { + $gapicClient->getLocation($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listLocationsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $locationsElement = new Location(); + $locations = [ + $locationsElement, + ]; + $expectedResponse = new ListLocationsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setLocations($locations); + $transport->addResponse($expectedResponse); + $request = new ListLocationsRequest(); + $response = $gapicClient->listLocations($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getLocations()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.location.Locations/ListLocations', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listLocationsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + $request = new ListLocationsRequest(); + try { + $gapicClient->listLocations($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createCertificateAsyncTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/createCertificateTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $description = 'description-1724546052'; + $pemCertificate = 'pemCertificate1234463984'; + $expectedResponse = new Certificate(); + $expectedResponse->setName($name); + $expectedResponse->setDescription($description); + $expectedResponse->setPemCertificate($pemCertificate); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createCertificateTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $certificateId = 'certificateId1494430915'; + $certificate = new Certificate(); + $request = (new CreateCertificateRequest()) + ->setParent($formattedParent) + ->setCertificateId($certificateId) + ->setCertificate($certificate); + $response = $gapicClient->createCertificateAsync($request)->wait(); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.certificatemanager.v1.CertificateManager/CreateCertificate', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getCertificateId(); + $this->assertProtobufEquals($certificateId, $actualValue); + $actualValue = $actualApiRequestObject->getCertificate(); + $this->assertProtobufEquals($certificate, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createCertificateTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } +} diff --git a/ConfidentialComputing/samples/V1/ConfidentialComputingClient/create_challenge.php b/ConfidentialComputing/samples/V1/ConfidentialComputingClient/create_challenge.php index cd694003c191..26af3b9671ba 100644 --- a/ConfidentialComputing/samples/V1/ConfidentialComputingClient/create_challenge.php +++ b/ConfidentialComputing/samples/V1/ConfidentialComputingClient/create_challenge.php @@ -25,7 +25,8 @@ // [START confidentialcomputing_v1_generated_ConfidentialComputing_CreateChallenge_sync] use Google\ApiCore\ApiException; use Google\Cloud\ConfidentialComputing\V1\Challenge; -use Google\Cloud\ConfidentialComputing\V1\ConfidentialComputingClient; +use Google\Cloud\ConfidentialComputing\V1\Client\ConfidentialComputingClient; +use Google\Cloud\ConfidentialComputing\V1\CreateChallengeRequest; /** * Creates a new Challenge in a given project and location. @@ -39,13 +40,16 @@ function create_challenge_sample(string $formattedParent): void // Create a client. $confidentialComputingClient = new ConfidentialComputingClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $challenge = new Challenge(); + $request = (new CreateChallengeRequest()) + ->setParent($formattedParent) + ->setChallenge($challenge); // Call the API and handle any network failures. try { /** @var Challenge $response */ - $response = $confidentialComputingClient->createChallenge($formattedParent, $challenge); + $response = $confidentialComputingClient->createChallenge($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ConfidentialComputing/samples/V1/ConfidentialComputingClient/get_location.php b/ConfidentialComputing/samples/V1/ConfidentialComputingClient/get_location.php index eac0ccdf2a1f..9e8b93c11b06 100644 --- a/ConfidentialComputing/samples/V1/ConfidentialComputingClient/get_location.php +++ b/ConfidentialComputing/samples/V1/ConfidentialComputingClient/get_location.php @@ -24,7 +24,8 @@ // [START confidentialcomputing_v1_generated_ConfidentialComputing_GetLocation_sync] use Google\ApiCore\ApiException; -use Google\Cloud\ConfidentialComputing\V1\ConfidentialComputingClient; +use Google\Cloud\ConfidentialComputing\V1\Client\ConfidentialComputingClient; +use Google\Cloud\Location\GetLocationRequest; use Google\Cloud\Location\Location; /** @@ -41,10 +42,13 @@ function get_location_sample(): void // Create a client. $confidentialComputingClient = new ConfidentialComputingClient(); + // Prepare the request message. + $request = new GetLocationRequest(); + // Call the API and handle any network failures. try { /** @var Location $response */ - $response = $confidentialComputingClient->getLocation(); + $response = $confidentialComputingClient->getLocation($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ConfidentialComputing/samples/V1/ConfidentialComputingClient/list_locations.php b/ConfidentialComputing/samples/V1/ConfidentialComputingClient/list_locations.php index 768c9dc8a49c..cdbfe21c4cf4 100644 --- a/ConfidentialComputing/samples/V1/ConfidentialComputingClient/list_locations.php +++ b/ConfidentialComputing/samples/V1/ConfidentialComputingClient/list_locations.php @@ -25,7 +25,8 @@ // [START confidentialcomputing_v1_generated_ConfidentialComputing_ListLocations_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; -use Google\Cloud\ConfidentialComputing\V1\ConfidentialComputingClient; +use Google\Cloud\ConfidentialComputing\V1\Client\ConfidentialComputingClient; +use Google\Cloud\Location\ListLocationsRequest; use Google\Cloud\Location\Location; /** @@ -42,10 +43,13 @@ function list_locations_sample(): void // Create a client. $confidentialComputingClient = new ConfidentialComputingClient(); + // Prepare the request message. + $request = new ListLocationsRequest(); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $confidentialComputingClient->listLocations(); + $response = $confidentialComputingClient->listLocations($request); /** @var Location $element */ foreach ($response as $element) { diff --git a/ConfidentialComputing/samples/V1/ConfidentialComputingClient/verify_attestation.php b/ConfidentialComputing/samples/V1/ConfidentialComputingClient/verify_attestation.php index 43e4a80637c6..87b339f829db 100644 --- a/ConfidentialComputing/samples/V1/ConfidentialComputingClient/verify_attestation.php +++ b/ConfidentialComputing/samples/V1/ConfidentialComputingClient/verify_attestation.php @@ -24,8 +24,9 @@ // [START confidentialcomputing_v1_generated_ConfidentialComputing_VerifyAttestation_sync] use Google\ApiCore\ApiException; -use Google\Cloud\ConfidentialComputing\V1\ConfidentialComputingClient; +use Google\Cloud\ConfidentialComputing\V1\Client\ConfidentialComputingClient; use Google\Cloud\ConfidentialComputing\V1\TpmAttestation; +use Google\Cloud\ConfidentialComputing\V1\VerifyAttestationRequest; use Google\Cloud\ConfidentialComputing\V1\VerifyAttestationResponse; /** @@ -41,13 +42,16 @@ function verify_attestation_sample(string $formattedChallenge): void // Create a client. $confidentialComputingClient = new ConfidentialComputingClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $tpmAttestation = new TpmAttestation(); + $request = (new VerifyAttestationRequest()) + ->setChallenge($formattedChallenge) + ->setTpmAttestation($tpmAttestation); // Call the API and handle any network failures. try { /** @var VerifyAttestationResponse $response */ - $response = $confidentialComputingClient->verifyAttestation($formattedChallenge, $tpmAttestation); + $response = $confidentialComputingClient->verifyAttestation($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ConfidentialComputing/src/V1/Client/BaseClient/ConfidentialComputingBaseClient.php b/ConfidentialComputing/src/V1/Client/BaseClient/ConfidentialComputingBaseClient.php new file mode 100644 index 000000000000..6f176adea03e --- /dev/null +++ b/ConfidentialComputing/src/V1/Client/BaseClient/ConfidentialComputingBaseClient.php @@ -0,0 +1,335 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/confidential_computing_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/confidential_computing_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/confidential_computing_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/confidential_computing_rest_client_config.php', + ], + ], + ]; + } + + /** + * Formats a string containing the fully-qualified path to represent a challenge + * resource. + * + * @param string $project + * @param string $location + * @param string $uuid + * + * @return string The formatted challenge resource. + */ + public static function challengeName(string $project, string $location, string $uuid): string + { + return self::getPathTemplate('challenge')->render([ + 'project' => $project, + 'location' => $location, + 'uuid' => $uuid, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a location + * resource. + * + * @param string $project + * @param string $location + * + * @return string The formatted location resource. + */ + public static function locationName(string $project, string $location): string + { + return self::getPathTemplate('location')->render([ + 'project' => $project, + 'location' => $location, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * Template: Pattern + * - challenge: projects/{project}/locations/{location}/challenges/{uuid} + * - location: projects/{project}/locations/{location} + * + * The optional $template argument can be supplied to specify a particular pattern, + * and must match one of the templates listed above. If no $template argument is + * provided, or if the $template argument does not match one of the templates + * listed, then parseName will check each of the supported templates, and return + * the first match. + * + * @param string $formattedName The formatted name string + * @param string $template Optional name of template to match + * + * @return array An associative array from name component IDs to component values. + * + * @throws ValidationException If $formattedName could not be matched. + */ + public static function parseName(string $formattedName, string $template = null): array + { + return self::parseFormattedName($formattedName, $template); + } + + /** + * Constructor. + * + * @param array $options { + * Optional. Options for configuring the service API wrapper. + * + * @type string $apiEndpoint + * The address of the API remote host. May optionally include the port, formatted + * as ":". Default 'confidentialcomputing.googleapis.com:443'. + * @type string|array|FetchAuthTokenInterface|CredentialsWrapper $credentials + * The credentials to be used by the client to authorize API calls. This option + * accepts either a path to a credentials file, or a decoded credentials file as a + * PHP array. + * *Advanced usage*: In addition, this option can also accept a pre-constructed + * {@see \Google\Auth\FetchAuthTokenInterface} object or + * {@see \Google\ApiCore\CredentialsWrapper} object. Note that when one of these + * objects are provided, any settings in $credentialsConfig will be ignored. + * @type array $credentialsConfig + * Options used to configure credentials, including auth token caching, for the + * client. For a full list of supporting configuration options, see + * {@see \Google\ApiCore\CredentialsWrapper::build()} . + * @type bool $disableRetries + * Determines whether or not retries defined by the client configuration should be + * disabled. Defaults to `false`. + * @type string|array $clientConfig + * Client method configuration, including retry settings. This option can be either + * a path to a JSON file, or a PHP array containing the decoded JSON data. By + * default this settings points to the default client config file, which is + * provided in the resources folder. + * @type string|TransportInterface $transport + * The transport used for executing network requests. May be either the string + * `rest` or `grpc`. Defaults to `grpc` if gRPC support is detected on the system. + * *Advanced usage*: Additionally, it is possible to pass in an already + * instantiated {@see \Google\ApiCore\Transport\TransportInterface} object. Note + * that when this object is provided, any settings in $transportConfig, and any + * $apiEndpoint setting, will be ignored. + * @type array $transportConfig + * Configuration options that will be used to construct the transport. Options for + * each supported transport type should be passed in a key for that transport. For + * example: + * $transportConfig = [ + * 'grpc' => [...], + * 'rest' => [...], + * ]; + * See the {@see \Google\ApiCore\Transport\GrpcTransport::build()} and + * {@see \Google\ApiCore\Transport\RestTransport::build()} methods for the + * supported options. + * @type callable $clientCertSource + * A callable which returns the client cert as a string. This can be used to + * provide a certificate and private key to the transport layer for mTLS. + * } + * + * @throws ValidationException + */ + public function __construct(array $options = []) + { + $clientOptions = $this->buildClientOptions($options); + $this->setClientOptions($clientOptions); + } + + /** Handles execution of the async variants for each documented method. */ + public function __call($method, $args) + { + if (substr($method, -5) !== 'Async') { + trigger_error('Call to undefined method ' . __CLASS__ . "::$method()", E_USER_ERROR); + } + + array_unshift($args, substr($method, 0, -5)); + return call_user_func_array([$this, 'startAsyncCall'], $args); + } + + /** + * Creates a new Challenge in a given project and location. + * + * The async variant is {@see self::createChallengeAsync()} . + * + * @param CreateChallengeRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Challenge + * + * @throws ApiException Thrown if the API call fails. + */ + public function createChallenge(CreateChallengeRequest $request, array $callOptions = []): Challenge + { + return $this->startApiCall('CreateChallenge', $request, $callOptions)->wait(); + } + + /** + * Verifies the provided attestation info, returning a signed OIDC token. + * + * The async variant is {@see self::verifyAttestationAsync()} . + * + * @param VerifyAttestationRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return VerifyAttestationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function verifyAttestation(VerifyAttestationRequest $request, array $callOptions = []): VerifyAttestationResponse + { + return $this->startApiCall('VerifyAttestation', $request, $callOptions)->wait(); + } + + /** + * Gets information about a location. + * + * The async variant is {@see self::getLocationAsync()} . + * + * @param GetLocationRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Location + * + * @throws ApiException Thrown if the API call fails. + */ + public function getLocation(GetLocationRequest $request, array $callOptions = []): Location + { + return $this->startApiCall('GetLocation', $request, $callOptions)->wait(); + } + + /** + * Lists information about the supported locations for this service. + * + * The async variant is {@see self::listLocationsAsync()} . + * + * @param ListLocationsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listLocations(ListLocationsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListLocations', $request, $callOptions); + } +} diff --git a/ConfidentialComputing/src/V1/Client/ConfidentialComputingClient.php b/ConfidentialComputing/src/V1/Client/ConfidentialComputingClient.php new file mode 100644 index 000000000000..0a044437a9be --- /dev/null +++ b/ConfidentialComputing/src/V1/Client/ConfidentialComputingClient.php @@ -0,0 +1,40 @@ +setParent($parent) + ->setChallenge($challenge); + } + /** * Constructor. * diff --git a/ConfidentialComputing/src/V1/resources/confidential_computing_descriptor_config.php b/ConfidentialComputing/src/V1/resources/confidential_computing_descriptor_config.php index 0b57f8eee133..8ab43815b29c 100644 --- a/ConfidentialComputing/src/V1/resources/confidential_computing_descriptor_config.php +++ b/ConfidentialComputing/src/V1/resources/confidential_computing_descriptor_config.php @@ -3,7 +3,41 @@ return [ 'interfaces' => [ 'google.cloud.confidentialcomputing.v1.ConfidentialComputing' => [ + 'CreateChallenge' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\ConfidentialComputing\V1\Challenge', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'VerifyAttestation' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\ConfidentialComputing\V1\VerifyAttestationResponse', + 'headerParams' => [ + [ + 'keyName' => 'challenge', + 'fieldAccessors' => [ + 'getChallenge', + ], + ], + ], + ], 'GetLocation' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Location\Location', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], 'interfaceOverride' => 'google.cloud.location.Locations', ], 'ListLocations' => [ @@ -15,8 +49,22 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getLocations', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\Location\ListLocationsResponse', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], 'interfaceOverride' => 'google.cloud.location.Locations', ], + 'templateMap' => [ + 'challenge' => 'projects/{project}/locations/{location}/challenges/{uuid}', + 'location' => 'projects/{project}/locations/{location}', + ], ], ], ]; diff --git a/ConfidentialComputing/tests/Unit/V1/Client/ConfidentialComputingClientTest.php b/ConfidentialComputing/tests/Unit/V1/Client/ConfidentialComputingClientTest.php new file mode 100644 index 000000000000..62c0199fa694 --- /dev/null +++ b/ConfidentialComputing/tests/Unit/V1/Client/ConfidentialComputingClientTest.php @@ -0,0 +1,374 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return ConfidentialComputingClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new ConfidentialComputingClient($options); + } + + /** @test */ + public function createChallengeTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $used = false; + $tpmNonce = 'tpmNonce-806632543'; + $expectedResponse = new Challenge(); + $expectedResponse->setName($name); + $expectedResponse->setUsed($used); + $expectedResponse->setTpmNonce($tpmNonce); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $challenge = new Challenge(); + $request = (new CreateChallengeRequest()) + ->setParent($formattedParent) + ->setChallenge($challenge); + $response = $gapicClient->createChallenge($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.confidentialcomputing.v1.ConfidentialComputing/CreateChallenge', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getChallenge(); + $this->assertProtobufEquals($challenge, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createChallengeExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $challenge = new Challenge(); + $request = (new CreateChallengeRequest()) + ->setParent($formattedParent) + ->setChallenge($challenge); + try { + $gapicClient->createChallenge($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function verifyAttestationTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $oidcClaimsToken = 'oidcClaimsToken1151909399'; + $expectedResponse = new VerifyAttestationResponse(); + $expectedResponse->setOidcClaimsToken($oidcClaimsToken); + $transport->addResponse($expectedResponse); + // Mock request + $formattedChallenge = $gapicClient->challengeName('[PROJECT]', '[LOCATION]', '[UUID]'); + $tpmAttestation = new TpmAttestation(); + $request = (new VerifyAttestationRequest()) + ->setChallenge($formattedChallenge) + ->setTpmAttestation($tpmAttestation); + $response = $gapicClient->verifyAttestation($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.confidentialcomputing.v1.ConfidentialComputing/VerifyAttestation', $actualFuncCall); + $actualValue = $actualRequestObject->getChallenge(); + $this->assertProtobufEquals($formattedChallenge, $actualValue); + $actualValue = $actualRequestObject->getTpmAttestation(); + $this->assertProtobufEquals($tpmAttestation, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function verifyAttestationExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedChallenge = $gapicClient->challengeName('[PROJECT]', '[LOCATION]', '[UUID]'); + $tpmAttestation = new TpmAttestation(); + $request = (new VerifyAttestationRequest()) + ->setChallenge($formattedChallenge) + ->setTpmAttestation($tpmAttestation); + try { + $gapicClient->verifyAttestation($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getLocationTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $locationId = 'locationId552319461'; + $displayName = 'displayName1615086568'; + $expectedResponse = new Location(); + $expectedResponse->setName($name2); + $expectedResponse->setLocationId($locationId); + $expectedResponse->setDisplayName($displayName); + $transport->addResponse($expectedResponse); + $request = new GetLocationRequest(); + $response = $gapicClient->getLocation($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.location.Locations/GetLocation', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getLocationExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + $request = new GetLocationRequest(); + try { + $gapicClient->getLocation($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listLocationsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $locationsElement = new Location(); + $locations = [ + $locationsElement, + ]; + $expectedResponse = new ListLocationsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setLocations($locations); + $transport->addResponse($expectedResponse); + $request = new ListLocationsRequest(); + $response = $gapicClient->listLocations($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getLocations()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.location.Locations/ListLocations', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listLocationsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + $request = new ListLocationsRequest(); + try { + $gapicClient->listLocations($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createChallengeAsyncTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $used = false; + $tpmNonce = 'tpmNonce-806632543'; + $expectedResponse = new Challenge(); + $expectedResponse->setName($name); + $expectedResponse->setUsed($used); + $expectedResponse->setTpmNonce($tpmNonce); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $challenge = new Challenge(); + $request = (new CreateChallengeRequest()) + ->setParent($formattedParent) + ->setChallenge($challenge); + $response = $gapicClient->createChallengeAsync($request)->wait(); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.confidentialcomputing.v1.ConfidentialComputing/CreateChallenge', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getChallenge(); + $this->assertProtobufEquals($challenge, $actualValue); + $this->assertTrue($transport->isExhausted()); + } +} diff --git a/DataCatalogLineage/samples/V1/LineageClient/batch_search_link_processes.php b/DataCatalogLineage/samples/V1/LineageClient/batch_search_link_processes.php index 5952d9f44088..fc1b44d52cd3 100644 --- a/DataCatalogLineage/samples/V1/LineageClient/batch_search_link_processes.php +++ b/DataCatalogLineage/samples/V1/LineageClient/batch_search_link_processes.php @@ -25,7 +25,8 @@ // [START datalineage_v1_generated_Lineage_BatchSearchLinkProcesses_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; -use Google\Cloud\DataCatalog\Lineage\V1\LineageClient; +use Google\Cloud\DataCatalog\Lineage\V1\BatchSearchLinkProcessesRequest; +use Google\Cloud\DataCatalog\Lineage\V1\Client\LineageClient; use Google\Cloud\DataCatalog\Lineage\V1\ProcessLinks; /** @@ -59,13 +60,16 @@ function batch_search_link_processes_sample(string $formattedParent, string $lin // Create a client. $lineageClient = new LineageClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $links = [$linksElement,]; + $request = (new BatchSearchLinkProcessesRequest()) + ->setParent($formattedParent) + ->setLinks($links); // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $lineageClient->batchSearchLinkProcesses($formattedParent, $links); + $response = $lineageClient->batchSearchLinkProcesses($request); /** @var ProcessLinks $element */ foreach ($response as $element) { diff --git a/DataCatalogLineage/samples/V1/LineageClient/create_lineage_event.php b/DataCatalogLineage/samples/V1/LineageClient/create_lineage_event.php index bf47bff0e5a3..708598c1828e 100644 --- a/DataCatalogLineage/samples/V1/LineageClient/create_lineage_event.php +++ b/DataCatalogLineage/samples/V1/LineageClient/create_lineage_event.php @@ -24,7 +24,8 @@ // [START datalineage_v1_generated_Lineage_CreateLineageEvent_sync] use Google\ApiCore\ApiException; -use Google\Cloud\DataCatalog\Lineage\V1\LineageClient; +use Google\Cloud\DataCatalog\Lineage\V1\Client\LineageClient; +use Google\Cloud\DataCatalog\Lineage\V1\CreateLineageEventRequest; use Google\Cloud\DataCatalog\Lineage\V1\LineageEvent; /** @@ -38,13 +39,16 @@ function create_lineage_event_sample(string $formattedParent): void // Create a client. $lineageClient = new LineageClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $lineageEvent = new LineageEvent(); + $request = (new CreateLineageEventRequest()) + ->setParent($formattedParent) + ->setLineageEvent($lineageEvent); // Call the API and handle any network failures. try { /** @var LineageEvent $response */ - $response = $lineageClient->createLineageEvent($formattedParent, $lineageEvent); + $response = $lineageClient->createLineageEvent($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/DataCatalogLineage/samples/V1/LineageClient/create_process.php b/DataCatalogLineage/samples/V1/LineageClient/create_process.php index 9ba016ce1887..de3bd8e24140 100644 --- a/DataCatalogLineage/samples/V1/LineageClient/create_process.php +++ b/DataCatalogLineage/samples/V1/LineageClient/create_process.php @@ -24,7 +24,8 @@ // [START datalineage_v1_generated_Lineage_CreateProcess_sync] use Google\ApiCore\ApiException; -use Google\Cloud\DataCatalog\Lineage\V1\LineageClient; +use Google\Cloud\DataCatalog\Lineage\V1\Client\LineageClient; +use Google\Cloud\DataCatalog\Lineage\V1\CreateProcessRequest; use Google\Cloud\DataCatalog\Lineage\V1\Process; /** @@ -39,13 +40,16 @@ function create_process_sample(string $formattedParent): void // Create a client. $lineageClient = new LineageClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $process = new Process(); + $request = (new CreateProcessRequest()) + ->setParent($formattedParent) + ->setProcess($process); // Call the API and handle any network failures. try { /** @var Process $response */ - $response = $lineageClient->createProcess($formattedParent, $process); + $response = $lineageClient->createProcess($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/DataCatalogLineage/samples/V1/LineageClient/create_run.php b/DataCatalogLineage/samples/V1/LineageClient/create_run.php index a2acbc02350a..0a001b418cd4 100644 --- a/DataCatalogLineage/samples/V1/LineageClient/create_run.php +++ b/DataCatalogLineage/samples/V1/LineageClient/create_run.php @@ -24,7 +24,8 @@ // [START datalineage_v1_generated_Lineage_CreateRun_sync] use Google\ApiCore\ApiException; -use Google\Cloud\DataCatalog\Lineage\V1\LineageClient; +use Google\Cloud\DataCatalog\Lineage\V1\Client\LineageClient; +use Google\Cloud\DataCatalog\Lineage\V1\CreateRunRequest; use Google\Cloud\DataCatalog\Lineage\V1\Run; use Google\Cloud\DataCatalog\Lineage\V1\Run\State; use Google\Protobuf\Timestamp; @@ -41,16 +42,19 @@ function create_run_sample(string $formattedParent, int $runState): void // Create a client. $lineageClient = new LineageClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $runStartTime = new Timestamp(); $run = (new Run()) ->setStartTime($runStartTime) ->setState($runState); + $request = (new CreateRunRequest()) + ->setParent($formattedParent) + ->setRun($run); // Call the API and handle any network failures. try { /** @var Run $response */ - $response = $lineageClient->createRun($formattedParent, $run); + $response = $lineageClient->createRun($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/DataCatalogLineage/samples/V1/LineageClient/delete_lineage_event.php b/DataCatalogLineage/samples/V1/LineageClient/delete_lineage_event.php index 70a2d2ae930a..a44e3cbec51a 100644 --- a/DataCatalogLineage/samples/V1/LineageClient/delete_lineage_event.php +++ b/DataCatalogLineage/samples/V1/LineageClient/delete_lineage_event.php @@ -24,7 +24,8 @@ // [START datalineage_v1_generated_Lineage_DeleteLineageEvent_sync] use Google\ApiCore\ApiException; -use Google\Cloud\DataCatalog\Lineage\V1\LineageClient; +use Google\Cloud\DataCatalog\Lineage\V1\Client\LineageClient; +use Google\Cloud\DataCatalog\Lineage\V1\DeleteLineageEventRequest; /** * Deletes the lineage event with the specified name. @@ -37,9 +38,13 @@ function delete_lineage_event_sample(string $formattedName): void // Create a client. $lineageClient = new LineageClient(); + // Prepare the request message. + $request = (new DeleteLineageEventRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { - $lineageClient->deleteLineageEvent($formattedName); + $lineageClient->deleteLineageEvent($request); printf('Call completed successfully.' . PHP_EOL); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/DataCatalogLineage/samples/V1/LineageClient/delete_process.php b/DataCatalogLineage/samples/V1/LineageClient/delete_process.php index ceb1afa2165a..9e847a3a522f 100644 --- a/DataCatalogLineage/samples/V1/LineageClient/delete_process.php +++ b/DataCatalogLineage/samples/V1/LineageClient/delete_process.php @@ -25,7 +25,8 @@ // [START datalineage_v1_generated_Lineage_DeleteProcess_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\DataCatalog\Lineage\V1\LineageClient; +use Google\Cloud\DataCatalog\Lineage\V1\Client\LineageClient; +use Google\Cloud\DataCatalog\Lineage\V1\DeleteProcessRequest; use Google\Rpc\Status; /** @@ -39,10 +40,14 @@ function delete_process_sample(string $formattedName): void // Create a client. $lineageClient = new LineageClient(); + // Prepare the request message. + $request = (new DeleteProcessRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $lineageClient->deleteProcess($formattedName); + $response = $lineageClient->deleteProcess($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/DataCatalogLineage/samples/V1/LineageClient/delete_run.php b/DataCatalogLineage/samples/V1/LineageClient/delete_run.php index a23d67e4066d..d54daa9b613f 100644 --- a/DataCatalogLineage/samples/V1/LineageClient/delete_run.php +++ b/DataCatalogLineage/samples/V1/LineageClient/delete_run.php @@ -25,7 +25,8 @@ // [START datalineage_v1_generated_Lineage_DeleteRun_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\DataCatalog\Lineage\V1\LineageClient; +use Google\Cloud\DataCatalog\Lineage\V1\Client\LineageClient; +use Google\Cloud\DataCatalog\Lineage\V1\DeleteRunRequest; use Google\Rpc\Status; /** @@ -39,10 +40,14 @@ function delete_run_sample(string $formattedName): void // Create a client. $lineageClient = new LineageClient(); + // Prepare the request message. + $request = (new DeleteRunRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $lineageClient->deleteRun($formattedName); + $response = $lineageClient->deleteRun($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/DataCatalogLineage/samples/V1/LineageClient/get_lineage_event.php b/DataCatalogLineage/samples/V1/LineageClient/get_lineage_event.php index 81bcb9ba8366..af73bcd87409 100644 --- a/DataCatalogLineage/samples/V1/LineageClient/get_lineage_event.php +++ b/DataCatalogLineage/samples/V1/LineageClient/get_lineage_event.php @@ -24,7 +24,8 @@ // [START datalineage_v1_generated_Lineage_GetLineageEvent_sync] use Google\ApiCore\ApiException; -use Google\Cloud\DataCatalog\Lineage\V1\LineageClient; +use Google\Cloud\DataCatalog\Lineage\V1\Client\LineageClient; +use Google\Cloud\DataCatalog\Lineage\V1\GetLineageEventRequest; use Google\Cloud\DataCatalog\Lineage\V1\LineageEvent; /** @@ -38,10 +39,14 @@ function get_lineage_event_sample(string $formattedName): void // Create a client. $lineageClient = new LineageClient(); + // Prepare the request message. + $request = (new GetLineageEventRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var LineageEvent $response */ - $response = $lineageClient->getLineageEvent($formattedName); + $response = $lineageClient->getLineageEvent($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/DataCatalogLineage/samples/V1/LineageClient/get_process.php b/DataCatalogLineage/samples/V1/LineageClient/get_process.php index fce2c4fa0b44..bbcb7725fbd8 100644 --- a/DataCatalogLineage/samples/V1/LineageClient/get_process.php +++ b/DataCatalogLineage/samples/V1/LineageClient/get_process.php @@ -24,7 +24,8 @@ // [START datalineage_v1_generated_Lineage_GetProcess_sync] use Google\ApiCore\ApiException; -use Google\Cloud\DataCatalog\Lineage\V1\LineageClient; +use Google\Cloud\DataCatalog\Lineage\V1\Client\LineageClient; +use Google\Cloud\DataCatalog\Lineage\V1\GetProcessRequest; use Google\Cloud\DataCatalog\Lineage\V1\Process; /** @@ -38,10 +39,14 @@ function get_process_sample(string $formattedName): void // Create a client. $lineageClient = new LineageClient(); + // Prepare the request message. + $request = (new GetProcessRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var Process $response */ - $response = $lineageClient->getProcess($formattedName); + $response = $lineageClient->getProcess($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/DataCatalogLineage/samples/V1/LineageClient/get_run.php b/DataCatalogLineage/samples/V1/LineageClient/get_run.php index e788648268d6..1c7f828f3747 100644 --- a/DataCatalogLineage/samples/V1/LineageClient/get_run.php +++ b/DataCatalogLineage/samples/V1/LineageClient/get_run.php @@ -24,7 +24,8 @@ // [START datalineage_v1_generated_Lineage_GetRun_sync] use Google\ApiCore\ApiException; -use Google\Cloud\DataCatalog\Lineage\V1\LineageClient; +use Google\Cloud\DataCatalog\Lineage\V1\Client\LineageClient; +use Google\Cloud\DataCatalog\Lineage\V1\GetRunRequest; use Google\Cloud\DataCatalog\Lineage\V1\Run; /** @@ -38,10 +39,14 @@ function get_run_sample(string $formattedName): void // Create a client. $lineageClient = new LineageClient(); + // Prepare the request message. + $request = (new GetRunRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var Run $response */ - $response = $lineageClient->getRun($formattedName); + $response = $lineageClient->getRun($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/DataCatalogLineage/samples/V1/LineageClient/list_lineage_events.php b/DataCatalogLineage/samples/V1/LineageClient/list_lineage_events.php index 0f275078c237..6d9d7d95410f 100644 --- a/DataCatalogLineage/samples/V1/LineageClient/list_lineage_events.php +++ b/DataCatalogLineage/samples/V1/LineageClient/list_lineage_events.php @@ -25,8 +25,9 @@ // [START datalineage_v1_generated_Lineage_ListLineageEvents_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; -use Google\Cloud\DataCatalog\Lineage\V1\LineageClient; +use Google\Cloud\DataCatalog\Lineage\V1\Client\LineageClient; use Google\Cloud\DataCatalog\Lineage\V1\LineageEvent; +use Google\Cloud\DataCatalog\Lineage\V1\ListLineageEventsRequest; /** * Lists lineage events in the given project and location. The list order is @@ -40,10 +41,14 @@ function list_lineage_events_sample(string $formattedParent): void // Create a client. $lineageClient = new LineageClient(); + // Prepare the request message. + $request = (new ListLineageEventsRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $lineageClient->listLineageEvents($formattedParent); + $response = $lineageClient->listLineageEvents($request); /** @var LineageEvent $element */ foreach ($response as $element) { diff --git a/DataCatalogLineage/samples/V1/LineageClient/list_processes.php b/DataCatalogLineage/samples/V1/LineageClient/list_processes.php index d36237304af8..cc374dcf0524 100644 --- a/DataCatalogLineage/samples/V1/LineageClient/list_processes.php +++ b/DataCatalogLineage/samples/V1/LineageClient/list_processes.php @@ -25,7 +25,8 @@ // [START datalineage_v1_generated_Lineage_ListProcesses_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; -use Google\Cloud\DataCatalog\Lineage\V1\LineageClient; +use Google\Cloud\DataCatalog\Lineage\V1\Client\LineageClient; +use Google\Cloud\DataCatalog\Lineage\V1\ListProcessesRequest; use Google\Cloud\DataCatalog\Lineage\V1\Process; /** @@ -41,10 +42,14 @@ function list_processes_sample(string $formattedParent): void // Create a client. $lineageClient = new LineageClient(); + // Prepare the request message. + $request = (new ListProcessesRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $lineageClient->listProcesses($formattedParent); + $response = $lineageClient->listProcesses($request); /** @var Process $element */ foreach ($response as $element) { diff --git a/DataCatalogLineage/samples/V1/LineageClient/list_runs.php b/DataCatalogLineage/samples/V1/LineageClient/list_runs.php index f8eae4ee2f01..966835a13579 100644 --- a/DataCatalogLineage/samples/V1/LineageClient/list_runs.php +++ b/DataCatalogLineage/samples/V1/LineageClient/list_runs.php @@ -25,7 +25,8 @@ // [START datalineage_v1_generated_Lineage_ListRuns_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; -use Google\Cloud\DataCatalog\Lineage\V1\LineageClient; +use Google\Cloud\DataCatalog\Lineage\V1\Client\LineageClient; +use Google\Cloud\DataCatalog\Lineage\V1\ListRunsRequest; use Google\Cloud\DataCatalog\Lineage\V1\Run; /** @@ -40,10 +41,14 @@ function list_runs_sample(string $formattedParent): void // Create a client. $lineageClient = new LineageClient(); + // Prepare the request message. + $request = (new ListRunsRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $lineageClient->listRuns($formattedParent); + $response = $lineageClient->listRuns($request); /** @var Run $element */ foreach ($response as $element) { diff --git a/DataCatalogLineage/samples/V1/LineageClient/search_links.php b/DataCatalogLineage/samples/V1/LineageClient/search_links.php index 55c85b5d62ad..84d588e16a42 100644 --- a/DataCatalogLineage/samples/V1/LineageClient/search_links.php +++ b/DataCatalogLineage/samples/V1/LineageClient/search_links.php @@ -25,8 +25,9 @@ // [START datalineage_v1_generated_Lineage_SearchLinks_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; -use Google\Cloud\DataCatalog\Lineage\V1\LineageClient; +use Google\Cloud\DataCatalog\Lineage\V1\Client\LineageClient; use Google\Cloud\DataCatalog\Lineage\V1\Link; +use Google\Cloud\DataCatalog\Lineage\V1\SearchLinksRequest; /** * Retrieve a list of links connected to a specific asset. @@ -47,10 +48,14 @@ function search_links_sample(string $formattedParent): void // Create a client. $lineageClient = new LineageClient(); + // Prepare the request message. + $request = (new SearchLinksRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $lineageClient->searchLinks($formattedParent); + $response = $lineageClient->searchLinks($request); /** @var Link $element */ foreach ($response as $element) { diff --git a/DataCatalogLineage/samples/V1/LineageClient/update_process.php b/DataCatalogLineage/samples/V1/LineageClient/update_process.php index 4a7fba9bb347..706330545719 100644 --- a/DataCatalogLineage/samples/V1/LineageClient/update_process.php +++ b/DataCatalogLineage/samples/V1/LineageClient/update_process.php @@ -24,8 +24,9 @@ // [START datalineage_v1_generated_Lineage_UpdateProcess_sync] use Google\ApiCore\ApiException; -use Google\Cloud\DataCatalog\Lineage\V1\LineageClient; +use Google\Cloud\DataCatalog\Lineage\V1\Client\LineageClient; use Google\Cloud\DataCatalog\Lineage\V1\Process; +use Google\Cloud\DataCatalog\Lineage\V1\UpdateProcessRequest; /** * Updates a process. @@ -41,13 +42,15 @@ function update_process_sample(): void // Create a client. $lineageClient = new LineageClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $process = new Process(); + $request = (new UpdateProcessRequest()) + ->setProcess($process); // Call the API and handle any network failures. try { /** @var Process $response */ - $response = $lineageClient->updateProcess($process); + $response = $lineageClient->updateProcess($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/DataCatalogLineage/samples/V1/LineageClient/update_run.php b/DataCatalogLineage/samples/V1/LineageClient/update_run.php index fe1047b63ef1..c8acb38a692d 100644 --- a/DataCatalogLineage/samples/V1/LineageClient/update_run.php +++ b/DataCatalogLineage/samples/V1/LineageClient/update_run.php @@ -24,9 +24,10 @@ // [START datalineage_v1_generated_Lineage_UpdateRun_sync] use Google\ApiCore\ApiException; -use Google\Cloud\DataCatalog\Lineage\V1\LineageClient; +use Google\Cloud\DataCatalog\Lineage\V1\Client\LineageClient; use Google\Cloud\DataCatalog\Lineage\V1\Run; use Google\Cloud\DataCatalog\Lineage\V1\Run\State; +use Google\Cloud\DataCatalog\Lineage\V1\UpdateRunRequest; use Google\Protobuf\Timestamp; /** @@ -39,16 +40,18 @@ function update_run_sample(int $runState): void // Create a client. $lineageClient = new LineageClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $runStartTime = new Timestamp(); $run = (new Run()) ->setStartTime($runStartTime) ->setState($runState); + $request = (new UpdateRunRequest()) + ->setRun($run); // Call the API and handle any network failures. try { /** @var Run $response */ - $response = $lineageClient->updateRun($run); + $response = $lineageClient->updateRun($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/DataCatalogLineage/src/V1/Client/BaseClient/LineageBaseClient.php b/DataCatalogLineage/src/V1/Client/BaseClient/LineageBaseClient.php new file mode 100644 index 000000000000..bfb4c1869801 --- /dev/null +++ b/DataCatalogLineage/src/V1/Client/BaseClient/LineageBaseClient.php @@ -0,0 +1,753 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/lineage_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/lineage_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/lineage_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/lineage_rest_client_config.php', + ], + ], + ]; + } + + /** + * Return an OperationsClient object with the same endpoint as $this. + * + * @return OperationsClient + */ + public function getOperationsClient() + { + return $this->operationsClient; + } + + /** + * Resume an existing long running operation that was previously started by a long + * running API method. If $methodName is not provided, or does not match a long + * running API method, then the operation can still be resumed, but the + * OperationResponse object will not deserialize the final response. + * + * @param string $operationName The name of the long running operation + * @param string $methodName The name of the method used to start the operation + * + * @return OperationResponse + */ + public function resumeOperation($operationName, $methodName = null) + { + $options = isset($this->descriptors[$methodName]['longRunning']) ? $this->descriptors[$methodName]['longRunning'] : []; + $operation = new OperationResponse($operationName, $this->getOperationsClient(), $options); + $operation->reload(); + return $operation; + } + + /** + * Formats a string containing the fully-qualified path to represent a + * lineage_event resource. + * + * @param string $project + * @param string $location + * @param string $process + * @param string $run + * @param string $lineageEvent + * + * @return string The formatted lineage_event resource. + */ + public static function lineageEventName(string $project, string $location, string $process, string $run, string $lineageEvent): string + { + return self::getPathTemplate('lineageEvent')->render([ + 'project' => $project, + 'location' => $location, + 'process' => $process, + 'run' => $run, + 'lineage_event' => $lineageEvent, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a location + * resource. + * + * @param string $project + * @param string $location + * + * @return string The formatted location resource. + */ + public static function locationName(string $project, string $location): string + { + return self::getPathTemplate('location')->render([ + 'project' => $project, + 'location' => $location, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a process + * resource. + * + * @param string $project + * @param string $location + * @param string $process + * + * @return string The formatted process resource. + */ + public static function processName(string $project, string $location, string $process): string + { + return self::getPathTemplate('process')->render([ + 'project' => $project, + 'location' => $location, + 'process' => $process, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a run + * resource. + * + * @param string $project + * @param string $location + * @param string $process + * @param string $run + * + * @return string The formatted run resource. + */ + public static function runName(string $project, string $location, string $process, string $run): string + { + return self::getPathTemplate('run')->render([ + 'project' => $project, + 'location' => $location, + 'process' => $process, + 'run' => $run, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * Template: Pattern + * - lineageEvent: projects/{project}/locations/{location}/processes/{process}/runs/{run}/lineageEvents/{lineage_event} + * - location: projects/{project}/locations/{location} + * - process: projects/{project}/locations/{location}/processes/{process} + * - run: projects/{project}/locations/{location}/processes/{process}/runs/{run} + * + * The optional $template argument can be supplied to specify a particular pattern, + * and must match one of the templates listed above. If no $template argument is + * provided, or if the $template argument does not match one of the templates + * listed, then parseName will check each of the supported templates, and return + * the first match. + * + * @param string $formattedName The formatted name string + * @param string $template Optional name of template to match + * + * @return array An associative array from name component IDs to component values. + * + * @throws ValidationException If $formattedName could not be matched. + */ + public static function parseName(string $formattedName, string $template = null): array + { + return self::parseFormattedName($formattedName, $template); + } + + /** + * Constructor. + * + * @param array $options { + * Optional. Options for configuring the service API wrapper. + * + * @type string $apiEndpoint + * The address of the API remote host. May optionally include the port, formatted + * as ":". Default 'datalineage.googleapis.com:443'. + * @type string|array|FetchAuthTokenInterface|CredentialsWrapper $credentials + * The credentials to be used by the client to authorize API calls. This option + * accepts either a path to a credentials file, or a decoded credentials file as a + * PHP array. + * *Advanced usage*: In addition, this option can also accept a pre-constructed + * {@see \Google\Auth\FetchAuthTokenInterface} object or + * {@see \Google\ApiCore\CredentialsWrapper} object. Note that when one of these + * objects are provided, any settings in $credentialsConfig will be ignored. + * @type array $credentialsConfig + * Options used to configure credentials, including auth token caching, for the + * client. For a full list of supporting configuration options, see + * {@see \Google\ApiCore\CredentialsWrapper::build()} . + * @type bool $disableRetries + * Determines whether or not retries defined by the client configuration should be + * disabled. Defaults to `false`. + * @type string|array $clientConfig + * Client method configuration, including retry settings. This option can be either + * a path to a JSON file, or a PHP array containing the decoded JSON data. By + * default this settings points to the default client config file, which is + * provided in the resources folder. + * @type string|TransportInterface $transport + * The transport used for executing network requests. May be either the string + * `rest` or `grpc`. Defaults to `grpc` if gRPC support is detected on the system. + * *Advanced usage*: Additionally, it is possible to pass in an already + * instantiated {@see \Google\ApiCore\Transport\TransportInterface} object. Note + * that when this object is provided, any settings in $transportConfig, and any + * $apiEndpoint setting, will be ignored. + * @type array $transportConfig + * Configuration options that will be used to construct the transport. Options for + * each supported transport type should be passed in a key for that transport. For + * example: + * $transportConfig = [ + * 'grpc' => [...], + * 'rest' => [...], + * ]; + * See the {@see \Google\ApiCore\Transport\GrpcTransport::build()} and + * {@see \Google\ApiCore\Transport\RestTransport::build()} methods for the + * supported options. + * @type callable $clientCertSource + * A callable which returns the client cert as a string. This can be used to + * provide a certificate and private key to the transport layer for mTLS. + * } + * + * @throws ValidationException + */ + public function __construct(array $options = []) + { + $clientOptions = $this->buildClientOptions($options); + $this->setClientOptions($clientOptions); + $this->operationsClient = $this->createOperationsClient($clientOptions); + } + + /** Handles execution of the async variants for each documented method. */ + public function __call($method, $args) + { + if (substr($method, -5) !== 'Async') { + trigger_error('Call to undefined method ' . __CLASS__ . "::$method()", E_USER_ERROR); + } + + array_unshift($args, substr($method, 0, -5)); + return call_user_func_array([$this, 'startAsyncCall'], $args); + } + + /** + * Retrieve information about LineageProcesses associated with specific + * links. LineageProcesses are transformation pipelines that result in data + * flowing from **source** to **target** assets. Links between assets + * represent this operation. + * + * If you have specific link names, you can use this method to + * verify which LineageProcesses contribute to creating those links. + * See the + * [SearchLinks][google.cloud.datacatalog.lineage.v1.Lineage.SearchLinks] + * method for more information on how to retrieve link name. + * + * You can retrieve the LineageProcess information in every project where you + * have the `datalineage.events.get` permission. The project provided in the + * URL is used for Billing and Quota. + * + * The async variant is {@see self::batchSearchLinkProcessesAsync()} . + * + * @param BatchSearchLinkProcessesRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function batchSearchLinkProcesses(BatchSearchLinkProcessesRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('BatchSearchLinkProcesses', $request, $callOptions); + } + + /** + * Creates a new lineage event. + * + * The async variant is {@see self::createLineageEventAsync()} . + * + * @param CreateLineageEventRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return LineageEvent + * + * @throws ApiException Thrown if the API call fails. + */ + public function createLineageEvent(CreateLineageEventRequest $request, array $callOptions = []): LineageEvent + { + return $this->startApiCall('CreateLineageEvent', $request, $callOptions)->wait(); + } + + /** + * Creates a new process. + * + * The async variant is {@see self::createProcessAsync()} . + * + * @param CreateProcessRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Process + * + * @throws ApiException Thrown if the API call fails. + */ + public function createProcess(CreateProcessRequest $request, array $callOptions = []): Process + { + return $this->startApiCall('CreateProcess', $request, $callOptions)->wait(); + } + + /** + * Creates a new run. + * + * The async variant is {@see self::createRunAsync()} . + * + * @param CreateRunRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Run + * + * @throws ApiException Thrown if the API call fails. + */ + public function createRun(CreateRunRequest $request, array $callOptions = []): Run + { + return $this->startApiCall('CreateRun', $request, $callOptions)->wait(); + } + + /** + * Deletes the lineage event with the specified name. + * + * The async variant is {@see self::deleteLineageEventAsync()} . + * + * @param DeleteLineageEventRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @throws ApiException Thrown if the API call fails. + */ + public function deleteLineageEvent(DeleteLineageEventRequest $request, array $callOptions = []): void + { + $this->startApiCall('DeleteLineageEvent', $request, $callOptions)->wait(); + } + + /** + * Deletes the process with the specified name. + * + * The async variant is {@see self::deleteProcessAsync()} . + * + * @param DeleteProcessRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function deleteProcess(DeleteProcessRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('DeleteProcess', $request, $callOptions)->wait(); + } + + /** + * Deletes the run with the specified name. + * + * The async variant is {@see self::deleteRunAsync()} . + * + * @param DeleteRunRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function deleteRun(DeleteRunRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('DeleteRun', $request, $callOptions)->wait(); + } + + /** + * Gets details of a specified lineage event. + * + * The async variant is {@see self::getLineageEventAsync()} . + * + * @param GetLineageEventRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return LineageEvent + * + * @throws ApiException Thrown if the API call fails. + */ + public function getLineageEvent(GetLineageEventRequest $request, array $callOptions = []): LineageEvent + { + return $this->startApiCall('GetLineageEvent', $request, $callOptions)->wait(); + } + + /** + * Gets the details of the specified process. + * + * The async variant is {@see self::getProcessAsync()} . + * + * @param GetProcessRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Process + * + * @throws ApiException Thrown if the API call fails. + */ + public function getProcess(GetProcessRequest $request, array $callOptions = []): Process + { + return $this->startApiCall('GetProcess', $request, $callOptions)->wait(); + } + + /** + * Gets the details of the specified run. + * + * The async variant is {@see self::getRunAsync()} . + * + * @param GetRunRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Run + * + * @throws ApiException Thrown if the API call fails. + */ + public function getRun(GetRunRequest $request, array $callOptions = []): Run + { + return $this->startApiCall('GetRun', $request, $callOptions)->wait(); + } + + /** + * Lists lineage events in the given project and location. The list order is + * not defined. + * + * The async variant is {@see self::listLineageEventsAsync()} . + * + * @param ListLineageEventsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listLineageEvents(ListLineageEventsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListLineageEvents', $request, $callOptions); + } + + /** + * List processes in the given project and location. List order is descending + * by insertion time. + * + * The async variant is {@see self::listProcessesAsync()} . + * + * @param ListProcessesRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listProcesses(ListProcessesRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListProcesses', $request, $callOptions); + } + + /** + * Lists runs in the given project and location. List order is descending by + * `start_time`. + * + * The async variant is {@see self::listRunsAsync()} . + * + * @param ListRunsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listRuns(ListRunsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListRuns', $request, $callOptions); + } + + /** + * Retrieve a list of links connected to a specific asset. + * Links represent the data flow between **source** (upstream) + * and **target** (downstream) assets in transformation pipelines. + * Links are stored in the same project as the Lineage Events that create + * them. + * + * You can retrieve links in every project where you have the + * `datalineage.events.get` permission. The project provided in the URL + * is used for Billing and Quota. + * + * The async variant is {@see self::searchLinksAsync()} . + * + * @param SearchLinksRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function searchLinks(SearchLinksRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('SearchLinks', $request, $callOptions); + } + + /** + * Updates a process. + * + * The async variant is {@see self::updateProcessAsync()} . + * + * @param UpdateProcessRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Process + * + * @throws ApiException Thrown if the API call fails. + */ + public function updateProcess(UpdateProcessRequest $request, array $callOptions = []): Process + { + return $this->startApiCall('UpdateProcess', $request, $callOptions)->wait(); + } + + /** + * Updates a run. + * + * The async variant is {@see self::updateRunAsync()} . + * + * @param UpdateRunRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Run + * + * @throws ApiException Thrown if the API call fails. + */ + public function updateRun(UpdateRunRequest $request, array $callOptions = []): Run + { + return $this->startApiCall('UpdateRun', $request, $callOptions)->wait(); + } +} diff --git a/DataCatalogLineage/src/V1/Client/LineageClient.php b/DataCatalogLineage/src/V1/Client/LineageClient.php new file mode 100644 index 000000000000..83eefbbcfb29 --- /dev/null +++ b/DataCatalogLineage/src/V1/Client/LineageClient.php @@ -0,0 +1,40 @@ +setParent($parent) + ->setLineageEvent($lineageEvent); + } + /** * Constructor. * diff --git a/DataCatalogLineage/src/V1/CreateProcessRequest.php b/DataCatalogLineage/src/V1/CreateProcessRequest.php index 5f978b6127c1..aa9d1ebaaee6 100644 --- a/DataCatalogLineage/src/V1/CreateProcessRequest.php +++ b/DataCatalogLineage/src/V1/CreateProcessRequest.php @@ -38,6 +38,23 @@ class CreateProcessRequest extends \Google\Protobuf\Internal\Message */ protected $request_id = ''; + /** + * @param string $parent Required. The name of the project and its location that should own the + * process. Please see + * {@see LineageClient::locationName()} for help formatting this field. + * @param \Google\Cloud\DataCatalog\Lineage\V1\Process $process Required. The process to create. + * + * @return \Google\Cloud\DataCatalog\Lineage\V1\CreateProcessRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\DataCatalog\Lineage\V1\Process $process): self + { + return (new self()) + ->setParent($parent) + ->setProcess($process); + } + /** * Constructor. * diff --git a/DataCatalogLineage/src/V1/CreateRunRequest.php b/DataCatalogLineage/src/V1/CreateRunRequest.php index aa2cd4b3cc83..67ac72ae8277 100644 --- a/DataCatalogLineage/src/V1/CreateRunRequest.php +++ b/DataCatalogLineage/src/V1/CreateRunRequest.php @@ -37,6 +37,22 @@ class CreateRunRequest extends \Google\Protobuf\Internal\Message */ protected $request_id = ''; + /** + * @param string $parent Required. The name of the process that should own the run. Please see + * {@see LineageClient::processName()} for help formatting this field. + * @param \Google\Cloud\DataCatalog\Lineage\V1\Run $run Required. The run to create. + * + * @return \Google\Cloud\DataCatalog\Lineage\V1\CreateRunRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\DataCatalog\Lineage\V1\Run $run): self + { + return (new self()) + ->setParent($parent) + ->setRun($run); + } + /** * Constructor. * diff --git a/DataCatalogLineage/src/V1/DeleteLineageEventRequest.php b/DataCatalogLineage/src/V1/DeleteLineageEventRequest.php index f2ccd7dd1fe9..18b9d21a24a2 100644 --- a/DataCatalogLineage/src/V1/DeleteLineageEventRequest.php +++ b/DataCatalogLineage/src/V1/DeleteLineageEventRequest.php @@ -30,6 +30,20 @@ class DeleteLineageEventRequest extends \Google\Protobuf\Internal\Message */ protected $allow_missing = false; + /** + * @param string $name Required. The name of the lineage event to delete. Please see + * {@see LineageClient::lineageEventName()} for help formatting this field. + * + * @return \Google\Cloud\DataCatalog\Lineage\V1\DeleteLineageEventRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/DataCatalogLineage/src/V1/DeleteProcessRequest.php b/DataCatalogLineage/src/V1/DeleteProcessRequest.php index 3def3790f9f9..088e68cffa5b 100644 --- a/DataCatalogLineage/src/V1/DeleteProcessRequest.php +++ b/DataCatalogLineage/src/V1/DeleteProcessRequest.php @@ -30,6 +30,20 @@ class DeleteProcessRequest extends \Google\Protobuf\Internal\Message */ protected $allow_missing = false; + /** + * @param string $name Required. The name of the process to delete. Please see + * {@see LineageClient::processName()} for help formatting this field. + * + * @return \Google\Cloud\DataCatalog\Lineage\V1\DeleteProcessRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/DataCatalogLineage/src/V1/DeleteRunRequest.php b/DataCatalogLineage/src/V1/DeleteRunRequest.php index ce082b1b958f..bcc506513f22 100644 --- a/DataCatalogLineage/src/V1/DeleteRunRequest.php +++ b/DataCatalogLineage/src/V1/DeleteRunRequest.php @@ -30,6 +30,20 @@ class DeleteRunRequest extends \Google\Protobuf\Internal\Message */ protected $allow_missing = false; + /** + * @param string $name Required. The name of the run to delete. Please see + * {@see LineageClient::runName()} for help formatting this field. + * + * @return \Google\Cloud\DataCatalog\Lineage\V1\DeleteRunRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/DataCatalogLineage/src/V1/GetLineageEventRequest.php b/DataCatalogLineage/src/V1/GetLineageEventRequest.php index 0c072d97fd85..bcfbb6140411 100644 --- a/DataCatalogLineage/src/V1/GetLineageEventRequest.php +++ b/DataCatalogLineage/src/V1/GetLineageEventRequest.php @@ -23,6 +23,20 @@ class GetLineageEventRequest extends \Google\Protobuf\Internal\Message */ protected $name = ''; + /** + * @param string $name Required. The name of the lineage event to get. Please see + * {@see LineageClient::lineageEventName()} for help formatting this field. + * + * @return \Google\Cloud\DataCatalog\Lineage\V1\GetLineageEventRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/DataCatalogLineage/src/V1/GetProcessRequest.php b/DataCatalogLineage/src/V1/GetProcessRequest.php index 5d38c9a90916..7f23ce58f182 100644 --- a/DataCatalogLineage/src/V1/GetProcessRequest.php +++ b/DataCatalogLineage/src/V1/GetProcessRequest.php @@ -23,6 +23,20 @@ class GetProcessRequest extends \Google\Protobuf\Internal\Message */ protected $name = ''; + /** + * @param string $name Required. The name of the process to get. Please see + * {@see LineageClient::processName()} for help formatting this field. + * + * @return \Google\Cloud\DataCatalog\Lineage\V1\GetProcessRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/DataCatalogLineage/src/V1/GetRunRequest.php b/DataCatalogLineage/src/V1/GetRunRequest.php index bb663ee0bb71..b0f0b84a2848 100644 --- a/DataCatalogLineage/src/V1/GetRunRequest.php +++ b/DataCatalogLineage/src/V1/GetRunRequest.php @@ -23,6 +23,20 @@ class GetRunRequest extends \Google\Protobuf\Internal\Message */ protected $name = ''; + /** + * @param string $name Required. The name of the run to get. Please see + * {@see LineageClient::runName()} for help formatting this field. + * + * @return \Google\Cloud\DataCatalog\Lineage\V1\GetRunRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/DataCatalogLineage/src/V1/ListLineageEventsRequest.php b/DataCatalogLineage/src/V1/ListLineageEventsRequest.php index 694c5bc8a303..02a1847041af 100644 --- a/DataCatalogLineage/src/V1/ListLineageEventsRequest.php +++ b/DataCatalogLineage/src/V1/ListLineageEventsRequest.php @@ -42,6 +42,20 @@ class ListLineageEventsRequest extends \Google\Protobuf\Internal\Message */ protected $page_token = ''; + /** + * @param string $parent Required. The name of the run that owns the collection of lineage events to + * get. Please see {@see LineageClient::runName()} for help formatting this field. + * + * @return \Google\Cloud\DataCatalog\Lineage\V1\ListLineageEventsRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/DataCatalogLineage/src/V1/ListProcessesRequest.php b/DataCatalogLineage/src/V1/ListProcessesRequest.php index 67c88e21b6f6..1b81bb00d128 100644 --- a/DataCatalogLineage/src/V1/ListProcessesRequest.php +++ b/DataCatalogLineage/src/V1/ListProcessesRequest.php @@ -42,6 +42,21 @@ class ListProcessesRequest extends \Google\Protobuf\Internal\Message */ protected $page_token = ''; + /** + * @param string $parent Required. The name of the project and its location that owns this + * collection of processes. Please see + * {@see LineageClient::locationName()} for help formatting this field. + * + * @return \Google\Cloud\DataCatalog\Lineage\V1\ListProcessesRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/DataCatalogLineage/src/V1/ListRunsRequest.php b/DataCatalogLineage/src/V1/ListRunsRequest.php index ec4af6ff6da4..6a762c1e9dcd 100644 --- a/DataCatalogLineage/src/V1/ListRunsRequest.php +++ b/DataCatalogLineage/src/V1/ListRunsRequest.php @@ -41,6 +41,20 @@ class ListRunsRequest extends \Google\Protobuf\Internal\Message */ protected $page_token = ''; + /** + * @param string $parent Required. The name of process that owns this collection of runs. Please see + * {@see LineageClient::processName()} for help formatting this field. + * + * @return \Google\Cloud\DataCatalog\Lineage\V1\ListRunsRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/DataCatalogLineage/src/V1/UpdateProcessRequest.php b/DataCatalogLineage/src/V1/UpdateProcessRequest.php index 15179d4514d5..9b26ec7372de 100644 --- a/DataCatalogLineage/src/V1/UpdateProcessRequest.php +++ b/DataCatalogLineage/src/V1/UpdateProcessRequest.php @@ -37,6 +37,24 @@ class UpdateProcessRequest extends \Google\Protobuf\Internal\Message */ protected $allow_missing = false; + /** + * @param \Google\Cloud\DataCatalog\Lineage\V1\Process $process Required. The lineage process to update. + * + * The process's `name` field is used to identify the process to update. + * @param \Google\Protobuf\FieldMask $updateMask The list of fields to update. Currently not used. The whole message is + * updated. + * + * @return \Google\Cloud\DataCatalog\Lineage\V1\UpdateProcessRequest + * + * @experimental + */ + public static function build(\Google\Cloud\DataCatalog\Lineage\V1\Process $process, \Google\Protobuf\FieldMask $updateMask): self + { + return (new self()) + ->setProcess($process) + ->setUpdateMask($updateMask); + } + /** * Constructor. * diff --git a/DataCatalogLineage/src/V1/UpdateRunRequest.php b/DataCatalogLineage/src/V1/UpdateRunRequest.php index cbe3dfc45b99..72b5866ce820 100644 --- a/DataCatalogLineage/src/V1/UpdateRunRequest.php +++ b/DataCatalogLineage/src/V1/UpdateRunRequest.php @@ -33,6 +33,27 @@ class UpdateRunRequest extends \Google\Protobuf\Internal\Message */ protected $update_mask = null; + /** + * @param \Google\Cloud\DataCatalog\Lineage\V1\Run $run Required. The lineage run to update. + * + * The run's `name` field is used to identify the run to update. + * + * Format: + * `projects/{project}/locations/{location}/processes/{process}/runs/{run}`. + * @param \Google\Protobuf\FieldMask $updateMask The list of fields to update. Currently not used. The whole message is + * updated. + * + * @return \Google\Cloud\DataCatalog\Lineage\V1\UpdateRunRequest + * + * @experimental + */ + public static function build(\Google\Cloud\DataCatalog\Lineage\V1\Run $run, \Google\Protobuf\FieldMask $updateMask): self + { + return (new self()) + ->setRun($run) + ->setUpdateMask($updateMask); + } + /** * Constructor. * diff --git a/DataCatalogLineage/src/V1/resources/lineage_descriptor_config.php b/DataCatalogLineage/src/V1/resources/lineage_descriptor_config.php index 200a251ac0ab..6ead216d0eb0 100644 --- a/DataCatalogLineage/src/V1/resources/lineage_descriptor_config.php +++ b/DataCatalogLineage/src/V1/resources/lineage_descriptor_config.php @@ -12,6 +12,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'DeleteRun' => [ 'longRunning' => [ @@ -22,6 +31,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'BatchSearchLinkProcesses' => [ 'pageStreaming' => [ @@ -32,6 +50,100 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getProcessLinks', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\DataCatalog\Lineage\V1\BatchSearchLinkProcessesResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'CreateLineageEvent' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\DataCatalog\Lineage\V1\LineageEvent', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'CreateProcess' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\DataCatalog\Lineage\V1\Process', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'CreateRun' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\DataCatalog\Lineage\V1\Run', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'DeleteLineageEvent' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Protobuf\GPBEmpty', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetLineageEvent' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\DataCatalog\Lineage\V1\LineageEvent', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetProcess' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\DataCatalog\Lineage\V1\Process', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetRun' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\DataCatalog\Lineage\V1\Run', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'ListLineageEvents' => [ 'pageStreaming' => [ @@ -42,6 +154,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getLineageEvents', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\DataCatalog\Lineage\V1\ListLineageEventsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ListProcesses' => [ 'pageStreaming' => [ @@ -52,6 +174,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getProcesses', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\DataCatalog\Lineage\V1\ListProcessesResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ListRuns' => [ 'pageStreaming' => [ @@ -62,6 +194,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getRuns', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\DataCatalog\Lineage\V1\ListRunsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'SearchLinks' => [ 'pageStreaming' => [ @@ -72,6 +214,48 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getLinks', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\DataCatalog\Lineage\V1\SearchLinksResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'UpdateProcess' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\DataCatalog\Lineage\V1\Process', + 'headerParams' => [ + [ + 'keyName' => 'process.name', + 'fieldAccessors' => [ + 'getProcess', + 'getName', + ], + ], + ], + ], + 'UpdateRun' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\DataCatalog\Lineage\V1\Run', + 'headerParams' => [ + [ + 'keyName' => 'run.name', + 'fieldAccessors' => [ + 'getRun', + 'getName', + ], + ], + ], + ], + 'templateMap' => [ + 'lineageEvent' => 'projects/{project}/locations/{location}/processes/{process}/runs/{run}/lineageEvents/{lineage_event}', + 'location' => 'projects/{project}/locations/{location}', + 'process' => 'projects/{project}/locations/{location}/processes/{process}', + 'run' => 'projects/{project}/locations/{location}/processes/{process}/runs/{run}', ], ], ], diff --git a/DataCatalogLineage/tests/Unit/V1/Client/LineageClientTest.php b/DataCatalogLineage/tests/Unit/V1/Client/LineageClientTest.php new file mode 100644 index 000000000000..456e2e8591ec --- /dev/null +++ b/DataCatalogLineage/tests/Unit/V1/Client/LineageClientTest.php @@ -0,0 +1,1361 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return LineageClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new LineageClient($options); + } + + /** @test */ + public function batchSearchLinkProcessesTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $processLinksElement = new ProcessLinks(); + $processLinks = [ + $processLinksElement, + ]; + $expectedResponse = new BatchSearchLinkProcessesResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setProcessLinks($processLinks); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $links = []; + $request = (new BatchSearchLinkProcessesRequest()) + ->setParent($formattedParent) + ->setLinks($links); + $response = $gapicClient->batchSearchLinkProcesses($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getProcessLinks()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datacatalog.lineage.v1.Lineage/BatchSearchLinkProcesses', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getLinks(); + $this->assertProtobufEquals($links, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function batchSearchLinkProcessesExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $links = []; + $request = (new BatchSearchLinkProcessesRequest()) + ->setParent($formattedParent) + ->setLinks($links); + try { + $gapicClient->batchSearchLinkProcesses($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createLineageEventTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $expectedResponse = new LineageEvent(); + $expectedResponse->setName($name); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->runName('[PROJECT]', '[LOCATION]', '[PROCESS]', '[RUN]'); + $lineageEvent = new LineageEvent(); + $request = (new CreateLineageEventRequest()) + ->setParent($formattedParent) + ->setLineageEvent($lineageEvent); + $response = $gapicClient->createLineageEvent($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datacatalog.lineage.v1.Lineage/CreateLineageEvent', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getLineageEvent(); + $this->assertProtobufEquals($lineageEvent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createLineageEventExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->runName('[PROJECT]', '[LOCATION]', '[PROCESS]', '[RUN]'); + $lineageEvent = new LineageEvent(); + $request = (new CreateLineageEventRequest()) + ->setParent($formattedParent) + ->setLineageEvent($lineageEvent); + try { + $gapicClient->createLineageEvent($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createProcessTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $displayName = 'displayName1615086568'; + $expectedResponse = new Process(); + $expectedResponse->setName($name); + $expectedResponse->setDisplayName($displayName); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $process = new Process(); + $request = (new CreateProcessRequest()) + ->setParent($formattedParent) + ->setProcess($process); + $response = $gapicClient->createProcess($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datacatalog.lineage.v1.Lineage/CreateProcess', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getProcess(); + $this->assertProtobufEquals($process, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createProcessExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $process = new Process(); + $request = (new CreateProcessRequest()) + ->setParent($formattedParent) + ->setProcess($process); + try { + $gapicClient->createProcess($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createRunTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $displayName = 'displayName1615086568'; + $expectedResponse = new Run(); + $expectedResponse->setName($name); + $expectedResponse->setDisplayName($displayName); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->processName('[PROJECT]', '[LOCATION]', '[PROCESS]'); + $run = new Run(); + $runStartTime = new Timestamp(); + $run->setStartTime($runStartTime); + $runState = State::UNKNOWN; + $run->setState($runState); + $request = (new CreateRunRequest()) + ->setParent($formattedParent) + ->setRun($run); + $response = $gapicClient->createRun($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datacatalog.lineage.v1.Lineage/CreateRun', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getRun(); + $this->assertProtobufEquals($run, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createRunExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->processName('[PROJECT]', '[LOCATION]', '[PROCESS]'); + $run = new Run(); + $runStartTime = new Timestamp(); + $run->setStartTime($runStartTime); + $runState = State::UNKNOWN; + $run->setState($runState); + $request = (new CreateRunRequest()) + ->setParent($formattedParent) + ->setRun($run); + try { + $gapicClient->createRun($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteLineageEventTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new GPBEmpty(); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->lineageEventName('[PROJECT]', '[LOCATION]', '[PROCESS]', '[RUN]', '[LINEAGE_EVENT]'); + $request = (new DeleteLineageEventRequest()) + ->setName($formattedName); + $gapicClient->deleteLineageEvent($request); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datacatalog.lineage.v1.Lineage/DeleteLineageEvent', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteLineageEventExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->lineageEventName('[PROJECT]', '[LOCATION]', '[PROCESS]', '[RUN]', '[LINEAGE_EVENT]'); + $request = (new DeleteLineageEventRequest()) + ->setName($formattedName); + try { + $gapicClient->deleteLineageEvent($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteProcessTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/deleteProcessTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new GPBEmpty(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/deleteProcessTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->processName('[PROJECT]', '[LOCATION]', '[PROCESS]'); + $request = (new DeleteProcessRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteProcess($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datacatalog.lineage.v1.Lineage/DeleteProcess', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteProcessTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function deleteProcessExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/deleteProcessTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->processName('[PROJECT]', '[LOCATION]', '[PROCESS]'); + $request = (new DeleteProcessRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteProcess($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteProcessTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function deleteRunTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/deleteRunTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new GPBEmpty(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/deleteRunTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->runName('[PROJECT]', '[LOCATION]', '[PROCESS]', '[RUN]'); + $request = (new DeleteRunRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteRun($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datacatalog.lineage.v1.Lineage/DeleteRun', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteRunTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function deleteRunExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/deleteRunTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->runName('[PROJECT]', '[LOCATION]', '[PROCESS]', '[RUN]'); + $request = (new DeleteRunRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteRun($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteRunTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function getLineageEventTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $expectedResponse = new LineageEvent(); + $expectedResponse->setName($name2); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->lineageEventName('[PROJECT]', '[LOCATION]', '[PROCESS]', '[RUN]', '[LINEAGE_EVENT]'); + $request = (new GetLineageEventRequest()) + ->setName($formattedName); + $response = $gapicClient->getLineageEvent($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datacatalog.lineage.v1.Lineage/GetLineageEvent', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getLineageEventExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->lineageEventName('[PROJECT]', '[LOCATION]', '[PROCESS]', '[RUN]', '[LINEAGE_EVENT]'); + $request = (new GetLineageEventRequest()) + ->setName($formattedName); + try { + $gapicClient->getLineageEvent($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getProcessTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $displayName = 'displayName1615086568'; + $expectedResponse = new Process(); + $expectedResponse->setName($name2); + $expectedResponse->setDisplayName($displayName); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->processName('[PROJECT]', '[LOCATION]', '[PROCESS]'); + $request = (new GetProcessRequest()) + ->setName($formattedName); + $response = $gapicClient->getProcess($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datacatalog.lineage.v1.Lineage/GetProcess', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getProcessExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->processName('[PROJECT]', '[LOCATION]', '[PROCESS]'); + $request = (new GetProcessRequest()) + ->setName($formattedName); + try { + $gapicClient->getProcess($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getRunTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $displayName = 'displayName1615086568'; + $expectedResponse = new Run(); + $expectedResponse->setName($name2); + $expectedResponse->setDisplayName($displayName); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->runName('[PROJECT]', '[LOCATION]', '[PROCESS]', '[RUN]'); + $request = (new GetRunRequest()) + ->setName($formattedName); + $response = $gapicClient->getRun($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datacatalog.lineage.v1.Lineage/GetRun', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getRunExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->runName('[PROJECT]', '[LOCATION]', '[PROCESS]', '[RUN]'); + $request = (new GetRunRequest()) + ->setName($formattedName); + try { + $gapicClient->getRun($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listLineageEventsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $lineageEventsElement = new LineageEvent(); + $lineageEvents = [ + $lineageEventsElement, + ]; + $expectedResponse = new ListLineageEventsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setLineageEvents($lineageEvents); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->runName('[PROJECT]', '[LOCATION]', '[PROCESS]', '[RUN]'); + $request = (new ListLineageEventsRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listLineageEvents($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getLineageEvents()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datacatalog.lineage.v1.Lineage/ListLineageEvents', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listLineageEventsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->runName('[PROJECT]', '[LOCATION]', '[PROCESS]', '[RUN]'); + $request = (new ListLineageEventsRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listLineageEvents($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listProcessesTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $processesElement = new Process(); + $processes = [ + $processesElement, + ]; + $expectedResponse = new ListProcessesResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setProcesses($processes); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListProcessesRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listProcesses($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getProcesses()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datacatalog.lineage.v1.Lineage/ListProcesses', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listProcessesExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListProcessesRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listProcesses($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listRunsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $runsElement = new Run(); + $runs = [ + $runsElement, + ]; + $expectedResponse = new ListRunsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setRuns($runs); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->processName('[PROJECT]', '[LOCATION]', '[PROCESS]'); + $request = (new ListRunsRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listRuns($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getRuns()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datacatalog.lineage.v1.Lineage/ListRuns', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listRunsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->processName('[PROJECT]', '[LOCATION]', '[PROCESS]'); + $request = (new ListRunsRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listRuns($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function searchLinksTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $linksElement = new Link(); + $links = [ + $linksElement, + ]; + $expectedResponse = new SearchLinksResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setLinks($links); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new SearchLinksRequest()) + ->setParent($formattedParent); + $response = $gapicClient->searchLinks($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getLinks()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datacatalog.lineage.v1.Lineage/SearchLinks', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function searchLinksExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new SearchLinksRequest()) + ->setParent($formattedParent); + try { + $gapicClient->searchLinks($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function updateProcessTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $displayName = 'displayName1615086568'; + $expectedResponse = new Process(); + $expectedResponse->setName($name); + $expectedResponse->setDisplayName($displayName); + $transport->addResponse($expectedResponse); + // Mock request + $process = new Process(); + $request = (new UpdateProcessRequest()) + ->setProcess($process); + $response = $gapicClient->updateProcess($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datacatalog.lineage.v1.Lineage/UpdateProcess', $actualFuncCall); + $actualValue = $actualRequestObject->getProcess(); + $this->assertProtobufEquals($process, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function updateProcessExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $process = new Process(); + $request = (new UpdateProcessRequest()) + ->setProcess($process); + try { + $gapicClient->updateProcess($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function updateRunTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $displayName = 'displayName1615086568'; + $expectedResponse = new Run(); + $expectedResponse->setName($name); + $expectedResponse->setDisplayName($displayName); + $transport->addResponse($expectedResponse); + // Mock request + $run = new Run(); + $runStartTime = new Timestamp(); + $run->setStartTime($runStartTime); + $runState = State::UNKNOWN; + $run->setState($runState); + $request = (new UpdateRunRequest()) + ->setRun($run); + $response = $gapicClient->updateRun($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datacatalog.lineage.v1.Lineage/UpdateRun', $actualFuncCall); + $actualValue = $actualRequestObject->getRun(); + $this->assertProtobufEquals($run, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function updateRunExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $run = new Run(); + $runStartTime = new Timestamp(); + $run->setStartTime($runStartTime); + $runState = State::UNKNOWN; + $run->setState($runState); + $request = (new UpdateRunRequest()) + ->setRun($run); + try { + $gapicClient->updateRun($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function batchSearchLinkProcessesAsyncTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $processLinksElement = new ProcessLinks(); + $processLinks = [ + $processLinksElement, + ]; + $expectedResponse = new BatchSearchLinkProcessesResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setProcessLinks($processLinks); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $links = []; + $request = (new BatchSearchLinkProcessesRequest()) + ->setParent($formattedParent) + ->setLinks($links); + $response = $gapicClient->batchSearchLinkProcessesAsync($request)->wait(); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getProcessLinks()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datacatalog.lineage.v1.Lineage/BatchSearchLinkProcesses', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getLinks(); + $this->assertProtobufEquals($links, $actualValue); + $this->assertTrue($transport->isExhausted()); + } +} diff --git a/DataFusion/samples/V1/DataFusionClient/create_instance.php b/DataFusion/samples/V1/DataFusionClient/create_instance.php index 5c895b889410..6cc9fad762bc 100644 --- a/DataFusion/samples/V1/DataFusionClient/create_instance.php +++ b/DataFusion/samples/V1/DataFusionClient/create_instance.php @@ -25,7 +25,8 @@ // [START datafusion_v1_generated_DataFusion_CreateInstance_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\DataFusion\V1\DataFusionClient; +use Google\Cloud\DataFusion\V1\Client\DataFusionClient; +use Google\Cloud\DataFusion\V1\CreateInstanceRequest; use Google\Cloud\DataFusion\V1\Instance; use Google\Rpc\Status; @@ -42,10 +43,15 @@ function create_instance_sample(string $formattedParent, string $instanceId): vo // Create a client. $dataFusionClient = new DataFusionClient(); + // Prepare the request message. + $request = (new CreateInstanceRequest()) + ->setParent($formattedParent) + ->setInstanceId($instanceId); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $dataFusionClient->createInstance($formattedParent, $instanceId); + $response = $dataFusionClient->createInstance($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/DataFusion/samples/V1/DataFusionClient/delete_instance.php b/DataFusion/samples/V1/DataFusionClient/delete_instance.php index a4e7aad4d373..9b208e78c9d3 100644 --- a/DataFusion/samples/V1/DataFusionClient/delete_instance.php +++ b/DataFusion/samples/V1/DataFusionClient/delete_instance.php @@ -25,7 +25,8 @@ // [START datafusion_v1_generated_DataFusion_DeleteInstance_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\DataFusion\V1\DataFusionClient; +use Google\Cloud\DataFusion\V1\Client\DataFusionClient; +use Google\Cloud\DataFusion\V1\DeleteInstanceRequest; use Google\Rpc\Status; /** @@ -40,10 +41,14 @@ function delete_instance_sample(string $formattedName): void // Create a client. $dataFusionClient = new DataFusionClient(); + // Prepare the request message. + $request = (new DeleteInstanceRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $dataFusionClient->deleteInstance($formattedName); + $response = $dataFusionClient->deleteInstance($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/DataFusion/samples/V1/DataFusionClient/get_instance.php b/DataFusion/samples/V1/DataFusionClient/get_instance.php index 0c9862427ba4..3bbce1a6ad61 100644 --- a/DataFusion/samples/V1/DataFusionClient/get_instance.php +++ b/DataFusion/samples/V1/DataFusionClient/get_instance.php @@ -24,7 +24,8 @@ // [START datafusion_v1_generated_DataFusion_GetInstance_sync] use Google\ApiCore\ApiException; -use Google\Cloud\DataFusion\V1\DataFusionClient; +use Google\Cloud\DataFusion\V1\Client\DataFusionClient; +use Google\Cloud\DataFusion\V1\GetInstanceRequest; use Google\Cloud\DataFusion\V1\Instance; /** @@ -39,10 +40,14 @@ function get_instance_sample(string $formattedName): void // Create a client. $dataFusionClient = new DataFusionClient(); + // Prepare the request message. + $request = (new GetInstanceRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var Instance $response */ - $response = $dataFusionClient->getInstance($formattedName); + $response = $dataFusionClient->getInstance($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/DataFusion/samples/V1/DataFusionClient/list_available_versions.php b/DataFusion/samples/V1/DataFusionClient/list_available_versions.php index 9bad814a6fac..8846006d3e51 100644 --- a/DataFusion/samples/V1/DataFusionClient/list_available_versions.php +++ b/DataFusion/samples/V1/DataFusionClient/list_available_versions.php @@ -25,7 +25,8 @@ // [START datafusion_v1_generated_DataFusion_ListAvailableVersions_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; -use Google\Cloud\DataFusion\V1\DataFusionClient; +use Google\Cloud\DataFusion\V1\Client\DataFusionClient; +use Google\Cloud\DataFusion\V1\ListAvailableVersionsRequest; use Google\Cloud\DataFusion\V1\Version; /** @@ -41,10 +42,14 @@ function list_available_versions_sample(string $formattedParent): void // Create a client. $dataFusionClient = new DataFusionClient(); + // Prepare the request message. + $request = (new ListAvailableVersionsRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $dataFusionClient->listAvailableVersions($formattedParent); + $response = $dataFusionClient->listAvailableVersions($request); /** @var Version $element */ foreach ($response as $element) { diff --git a/DataFusion/samples/V1/DataFusionClient/list_instances.php b/DataFusion/samples/V1/DataFusionClient/list_instances.php index f8ff5c64aea6..26e6eb16b8ab 100644 --- a/DataFusion/samples/V1/DataFusionClient/list_instances.php +++ b/DataFusion/samples/V1/DataFusionClient/list_instances.php @@ -25,8 +25,9 @@ // [START datafusion_v1_generated_DataFusion_ListInstances_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; -use Google\Cloud\DataFusion\V1\DataFusionClient; +use Google\Cloud\DataFusion\V1\Client\DataFusionClient; use Google\Cloud\DataFusion\V1\Instance; +use Google\Cloud\DataFusion\V1\ListInstancesRequest; /** * Lists Data Fusion instances in the specified project and location. @@ -42,10 +43,14 @@ function list_instances_sample(string $formattedParent): void // Create a client. $dataFusionClient = new DataFusionClient(); + // Prepare the request message. + $request = (new ListInstancesRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $dataFusionClient->listInstances($formattedParent); + $response = $dataFusionClient->listInstances($request); /** @var Instance $element */ foreach ($response as $element) { diff --git a/DataFusion/samples/V1/DataFusionClient/restart_instance.php b/DataFusion/samples/V1/DataFusionClient/restart_instance.php index 2b2da4022625..2f82512c90c7 100644 --- a/DataFusion/samples/V1/DataFusionClient/restart_instance.php +++ b/DataFusion/samples/V1/DataFusionClient/restart_instance.php @@ -25,8 +25,9 @@ // [START datafusion_v1_generated_DataFusion_RestartInstance_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\DataFusion\V1\DataFusionClient; +use Google\Cloud\DataFusion\V1\Client\DataFusionClient; use Google\Cloud\DataFusion\V1\Instance; +use Google\Cloud\DataFusion\V1\RestartInstanceRequest; use Google\Rpc\Status; /** @@ -42,10 +43,14 @@ function restart_instance_sample(string $formattedName): void // Create a client. $dataFusionClient = new DataFusionClient(); + // Prepare the request message. + $request = (new RestartInstanceRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $dataFusionClient->restartInstance($formattedName); + $response = $dataFusionClient->restartInstance($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/DataFusion/samples/V1/DataFusionClient/update_instance.php b/DataFusion/samples/V1/DataFusionClient/update_instance.php index 9e87f40dd5f3..976ffa8dc74d 100644 --- a/DataFusion/samples/V1/DataFusionClient/update_instance.php +++ b/DataFusion/samples/V1/DataFusionClient/update_instance.php @@ -25,9 +25,10 @@ // [START datafusion_v1_generated_DataFusion_UpdateInstance_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\DataFusion\V1\DataFusionClient; +use Google\Cloud\DataFusion\V1\Client\DataFusionClient; use Google\Cloud\DataFusion\V1\Instance; use Google\Cloud\DataFusion\V1\Instance\Type; +use Google\Cloud\DataFusion\V1\UpdateInstanceRequest; use Google\Rpc\Status; /** @@ -40,14 +41,16 @@ function update_instance_sample(int $instanceType): void // Create a client. $dataFusionClient = new DataFusionClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $instance = (new Instance()) ->setType($instanceType); + $request = (new UpdateInstanceRequest()) + ->setInstance($instance); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $dataFusionClient->updateInstance($instance); + $response = $dataFusionClient->updateInstance($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/DataFusion/src/V1/Client/BaseClient/DataFusionBaseClient.php b/DataFusion/src/V1/Client/BaseClient/DataFusionBaseClient.php new file mode 100644 index 000000000000..4215628809cf --- /dev/null +++ b/DataFusion/src/V1/Client/BaseClient/DataFusionBaseClient.php @@ -0,0 +1,472 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/data_fusion_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/data_fusion_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/data_fusion_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/data_fusion_rest_client_config.php', + ], + ], + ]; + } + + /** + * Return an OperationsClient object with the same endpoint as $this. + * + * @return OperationsClient + */ + public function getOperationsClient() + { + return $this->operationsClient; + } + + /** + * Resume an existing long running operation that was previously started by a long + * running API method. If $methodName is not provided, or does not match a long + * running API method, then the operation can still be resumed, but the + * OperationResponse object will not deserialize the final response. + * + * @param string $operationName The name of the long running operation + * @param string $methodName The name of the method used to start the operation + * + * @return OperationResponse + */ + public function resumeOperation($operationName, $methodName = null) + { + $options = isset($this->descriptors[$methodName]['longRunning']) ? $this->descriptors[$methodName]['longRunning'] : []; + $operation = new OperationResponse($operationName, $this->getOperationsClient(), $options); + $operation->reload(); + return $operation; + } + + /** + * Formats a string containing the fully-qualified path to represent a crypto_key + * resource. + * + * @param string $project + * @param string $location + * @param string $keyRing + * @param string $cryptoKey + * + * @return string The formatted crypto_key resource. + */ + public static function cryptoKeyName(string $project, string $location, string $keyRing, string $cryptoKey): string + { + return self::getPathTemplate('cryptoKey')->render([ + 'project' => $project, + 'location' => $location, + 'key_ring' => $keyRing, + 'crypto_key' => $cryptoKey, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a instance + * resource. + * + * @param string $project + * @param string $location + * @param string $instance + * + * @return string The formatted instance resource. + */ + public static function instanceName(string $project, string $location, string $instance): string + { + return self::getPathTemplate('instance')->render([ + 'project' => $project, + 'location' => $location, + 'instance' => $instance, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a location + * resource. + * + * @param string $project + * @param string $location + * + * @return string The formatted location resource. + */ + public static function locationName(string $project, string $location): string + { + return self::getPathTemplate('location')->render([ + 'project' => $project, + 'location' => $location, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * Template: Pattern + * - cryptoKey: projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key} + * - instance: projects/{project}/locations/{location}/instances/{instance} + * - location: projects/{project}/locations/{location} + * + * The optional $template argument can be supplied to specify a particular pattern, + * and must match one of the templates listed above. If no $template argument is + * provided, or if the $template argument does not match one of the templates + * listed, then parseName will check each of the supported templates, and return + * the first match. + * + * @param string $formattedName The formatted name string + * @param string $template Optional name of template to match + * + * @return array An associative array from name component IDs to component values. + * + * @throws ValidationException If $formattedName could not be matched. + */ + public static function parseName(string $formattedName, string $template = null): array + { + return self::parseFormattedName($formattedName, $template); + } + + /** + * Constructor. + * + * @param array $options { + * Optional. Options for configuring the service API wrapper. + * + * @type string $apiEndpoint + * The address of the API remote host. May optionally include the port, formatted + * as ":". Default 'datafusion.googleapis.com:443'. + * @type string|array|FetchAuthTokenInterface|CredentialsWrapper $credentials + * The credentials to be used by the client to authorize API calls. This option + * accepts either a path to a credentials file, or a decoded credentials file as a + * PHP array. + * *Advanced usage*: In addition, this option can also accept a pre-constructed + * {@see \Google\Auth\FetchAuthTokenInterface} object or + * {@see \Google\ApiCore\CredentialsWrapper} object. Note that when one of these + * objects are provided, any settings in $credentialsConfig will be ignored. + * @type array $credentialsConfig + * Options used to configure credentials, including auth token caching, for the + * client. For a full list of supporting configuration options, see + * {@see \Google\ApiCore\CredentialsWrapper::build()} . + * @type bool $disableRetries + * Determines whether or not retries defined by the client configuration should be + * disabled. Defaults to `false`. + * @type string|array $clientConfig + * Client method configuration, including retry settings. This option can be either + * a path to a JSON file, or a PHP array containing the decoded JSON data. By + * default this settings points to the default client config file, which is + * provided in the resources folder. + * @type string|TransportInterface $transport + * The transport used for executing network requests. May be either the string + * `rest` or `grpc`. Defaults to `grpc` if gRPC support is detected on the system. + * *Advanced usage*: Additionally, it is possible to pass in an already + * instantiated {@see \Google\ApiCore\Transport\TransportInterface} object. Note + * that when this object is provided, any settings in $transportConfig, and any + * $apiEndpoint setting, will be ignored. + * @type array $transportConfig + * Configuration options that will be used to construct the transport. Options for + * each supported transport type should be passed in a key for that transport. For + * example: + * $transportConfig = [ + * 'grpc' => [...], + * 'rest' => [...], + * ]; + * See the {@see \Google\ApiCore\Transport\GrpcTransport::build()} and + * {@see \Google\ApiCore\Transport\RestTransport::build()} methods for the + * supported options. + * @type callable $clientCertSource + * A callable which returns the client cert as a string. This can be used to + * provide a certificate and private key to the transport layer for mTLS. + * } + * + * @throws ValidationException + */ + public function __construct(array $options = []) + { + $clientOptions = $this->buildClientOptions($options); + $this->setClientOptions($clientOptions); + $this->operationsClient = $this->createOperationsClient($clientOptions); + } + + /** Handles execution of the async variants for each documented method. */ + public function __call($method, $args) + { + if (substr($method, -5) !== 'Async') { + trigger_error('Call to undefined method ' . __CLASS__ . "::$method()", E_USER_ERROR); + } + + array_unshift($args, substr($method, 0, -5)); + return call_user_func_array([$this, 'startAsyncCall'], $args); + } + + /** + * Creates a new Data Fusion instance in the specified project and location. + * + * The async variant is {@see self::createInstanceAsync()} . + * + * @param CreateInstanceRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function createInstance(CreateInstanceRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('CreateInstance', $request, $callOptions)->wait(); + } + + /** + * Deletes a single Date Fusion instance. + * + * The async variant is {@see self::deleteInstanceAsync()} . + * + * @param DeleteInstanceRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function deleteInstance(DeleteInstanceRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('DeleteInstance', $request, $callOptions)->wait(); + } + + /** + * Gets details of a single Data Fusion instance. + * + * The async variant is {@see self::getInstanceAsync()} . + * + * @param GetInstanceRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Instance + * + * @throws ApiException Thrown if the API call fails. + */ + public function getInstance(GetInstanceRequest $request, array $callOptions = []): Instance + { + return $this->startApiCall('GetInstance', $request, $callOptions)->wait(); + } + + /** + * Lists possible versions for Data Fusion instances in the specified project + * and location. + * + * The async variant is {@see self::listAvailableVersionsAsync()} . + * + * @param ListAvailableVersionsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listAvailableVersions(ListAvailableVersionsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListAvailableVersions', $request, $callOptions); + } + + /** + * Lists Data Fusion instances in the specified project and location. + * + * The async variant is {@see self::listInstancesAsync()} . + * + * @param ListInstancesRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listInstances(ListInstancesRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListInstances', $request, $callOptions); + } + + /** + * Restart a single Data Fusion instance. + * At the end of an operation instance is fully restarted. + * + * The async variant is {@see self::restartInstanceAsync()} . + * + * @param RestartInstanceRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function restartInstance(RestartInstanceRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('RestartInstance', $request, $callOptions)->wait(); + } + + /** + * Updates a single Data Fusion instance. + * + * The async variant is {@see self::updateInstanceAsync()} . + * + * @param UpdateInstanceRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function updateInstance(UpdateInstanceRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('UpdateInstance', $request, $callOptions)->wait(); + } +} diff --git a/DataFusion/src/V1/Client/DataFusionClient.php b/DataFusion/src/V1/Client/DataFusionClient.php new file mode 100644 index 000000000000..0952b882198e --- /dev/null +++ b/DataFusion/src/V1/Client/DataFusionClient.php @@ -0,0 +1,40 @@ +setParent($parent) + ->setInstance($instance) + ->setInstanceId($instanceId); + } + /** * Constructor. * diff --git a/DataFusion/src/V1/DeleteInstanceRequest.php b/DataFusion/src/V1/DeleteInstanceRequest.php index 12e5a6b271d6..41eb160a0659 100644 --- a/DataFusion/src/V1/DeleteInstanceRequest.php +++ b/DataFusion/src/V1/DeleteInstanceRequest.php @@ -23,6 +23,21 @@ class DeleteInstanceRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The instance resource name in the format + * projects/{project}/locations/{location}/instances/{instance} + * Please see {@see DataFusionClient::instanceName()} for help formatting this field. + * + * @return \Google\Cloud\DataFusion\V1\DeleteInstanceRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/DataFusion/src/V1/ListAvailableVersionsRequest.php b/DataFusion/src/V1/ListAvailableVersionsRequest.php index 3412f677fc53..1d58816f2f8e 100644 --- a/DataFusion/src/V1/ListAvailableVersionsRequest.php +++ b/DataFusion/src/V1/ListAvailableVersionsRequest.php @@ -44,6 +44,21 @@ class ListAvailableVersionsRequest extends \Google\Protobuf\Internal\Message */ private $latest_patch_only = false; + /** + * @param string $parent Required. The project and location for which to retrieve instance information + * in the format projects/{project}/locations/{location}. Please see + * {@see DataFusionClient::locationName()} for help formatting this field. + * + * @return \Google\Cloud\DataFusion\V1\ListAvailableVersionsRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/DataFusion/src/V1/UpdateInstanceRequest.php b/DataFusion/src/V1/UpdateInstanceRequest.php index 15ec9428ba13..2962cebafac8 100644 --- a/DataFusion/src/V1/UpdateInstanceRequest.php +++ b/DataFusion/src/V1/UpdateInstanceRequest.php @@ -37,6 +37,28 @@ class UpdateInstanceRequest extends \Google\Protobuf\Internal\Message */ private $update_mask = null; + /** + * @param \Google\Cloud\DataFusion\V1\Instance $instance Required. The instance resource that replaces the resource on the server. Currently, + * Data Fusion only allows replacing labels, options, and stack driver + * settings. All other fields will be ignored. + * @param \Google\Protobuf\FieldMask $updateMask Field mask is used to specify the fields that the update will overwrite + * in an instance resource. The fields specified in the update_mask are + * relative to the resource, not the full request. + * A field will be overwritten if it is in the mask. + * If the user does not provide a mask, all the supported fields (labels, + * options, and version currently) will be overwritten. + * + * @return \Google\Cloud\DataFusion\V1\UpdateInstanceRequest + * + * @experimental + */ + public static function build(\Google\Cloud\DataFusion\V1\Instance $instance, \Google\Protobuf\FieldMask $updateMask): self + { + return (new self()) + ->setInstance($instance) + ->setUpdateMask($updateMask); + } + /** * Constructor. * diff --git a/DataFusion/src/V1/resources/data_fusion_descriptor_config.php b/DataFusion/src/V1/resources/data_fusion_descriptor_config.php index 1243e9fd3f4f..34fbd52f9e1d 100644 --- a/DataFusion/src/V1/resources/data_fusion_descriptor_config.php +++ b/DataFusion/src/V1/resources/data_fusion_descriptor_config.php @@ -12,6 +12,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'DeleteInstance' => [ 'longRunning' => [ @@ -22,6 +31,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'RestartInstance' => [ 'longRunning' => [ @@ -32,6 +50,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'UpdateInstance' => [ 'longRunning' => [ @@ -42,6 +69,28 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'instance.name', + 'fieldAccessors' => [ + 'getInstance', + 'getName', + ], + ], + ], + ], + 'GetInstance' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\DataFusion\V1\Instance', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'ListAvailableVersions' => [ 'pageStreaming' => [ @@ -52,6 +101,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getAvailableVersions', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\DataFusion\V1\ListAvailableVersionsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ListInstances' => [ 'pageStreaming' => [ @@ -62,6 +121,21 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getInstances', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\DataFusion\V1\ListInstancesResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'templateMap' => [ + 'cryptoKey' => 'projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key}', + 'instance' => 'projects/{project}/locations/{location}/instances/{instance}', + 'location' => 'projects/{project}/locations/{location}', ], ], ], diff --git a/DataFusion/tests/Unit/V1/Client/DataFusionClientTest.php b/DataFusion/tests/Unit/V1/Client/DataFusionClientTest.php new file mode 100644 index 000000000000..2330c41f6fd9 --- /dev/null +++ b/DataFusion/tests/Unit/V1/Client/DataFusionClientTest.php @@ -0,0 +1,1015 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return DataFusionClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new DataFusionClient($options); + } + + /** @test */ + public function createInstanceTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/createInstanceTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $description = 'description-1724546052'; + $enableStackdriverLogging = true; + $enableStackdriverMonitoring = false; + $privateInstance = false; + $stateMessage = 'stateMessage29641305'; + $serviceEndpoint = 'serviceEndpoint-676052001'; + $zone = 'zone3744684'; + $version = 'version351608024'; + $serviceAccount = 'serviceAccount-1948028253'; + $displayName = 'displayName1615086568'; + $apiEndpoint = 'apiEndpoint-1381395942'; + $gcsBucket = 'gcsBucket-1720393710'; + $p4ServiceAccount = 'p4ServiceAccount-1554461144'; + $tenantProjectId = 'tenantProjectId-2129337674'; + $dataprocServiceAccount = 'dataprocServiceAccount-493324700'; + $enableRbac = true; + $expectedResponse = new Instance(); + $expectedResponse->setName($name); + $expectedResponse->setDescription($description); + $expectedResponse->setEnableStackdriverLogging($enableStackdriverLogging); + $expectedResponse->setEnableStackdriverMonitoring($enableStackdriverMonitoring); + $expectedResponse->setPrivateInstance($privateInstance); + $expectedResponse->setStateMessage($stateMessage); + $expectedResponse->setServiceEndpoint($serviceEndpoint); + $expectedResponse->setZone($zone); + $expectedResponse->setVersion($version); + $expectedResponse->setServiceAccount($serviceAccount); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setApiEndpoint($apiEndpoint); + $expectedResponse->setGcsBucket($gcsBucket); + $expectedResponse->setP4ServiceAccount($p4ServiceAccount); + $expectedResponse->setTenantProjectId($tenantProjectId); + $expectedResponse->setDataprocServiceAccount($dataprocServiceAccount); + $expectedResponse->setEnableRbac($enableRbac); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createInstanceTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $instanceId = 'instanceId-2101995259'; + $request = (new CreateInstanceRequest()) + ->setParent($formattedParent) + ->setInstanceId($instanceId); + $response = $gapicClient->createInstance($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datafusion.v1.DataFusion/CreateInstance', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getInstanceId(); + $this->assertProtobufEquals($instanceId, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createInstanceTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function createInstanceExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/createInstanceTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $instanceId = 'instanceId-2101995259'; + $request = (new CreateInstanceRequest()) + ->setParent($formattedParent) + ->setInstanceId($instanceId); + $response = $gapicClient->createInstance($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createInstanceTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function deleteInstanceTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/deleteInstanceTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new GPBEmpty(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/deleteInstanceTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->instanceName('[PROJECT]', '[LOCATION]', '[INSTANCE]'); + $request = (new DeleteInstanceRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteInstance($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datafusion.v1.DataFusion/DeleteInstance', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteInstanceTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function deleteInstanceExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/deleteInstanceTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->instanceName('[PROJECT]', '[LOCATION]', '[INSTANCE]'); + $request = (new DeleteInstanceRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteInstance($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteInstanceTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function getInstanceTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $description = 'description-1724546052'; + $enableStackdriverLogging = true; + $enableStackdriverMonitoring = false; + $privateInstance = false; + $stateMessage = 'stateMessage29641305'; + $serviceEndpoint = 'serviceEndpoint-676052001'; + $zone = 'zone3744684'; + $version = 'version351608024'; + $serviceAccount = 'serviceAccount-1948028253'; + $displayName = 'displayName1615086568'; + $apiEndpoint = 'apiEndpoint-1381395942'; + $gcsBucket = 'gcsBucket-1720393710'; + $p4ServiceAccount = 'p4ServiceAccount-1554461144'; + $tenantProjectId = 'tenantProjectId-2129337674'; + $dataprocServiceAccount = 'dataprocServiceAccount-493324700'; + $enableRbac = true; + $expectedResponse = new Instance(); + $expectedResponse->setName($name2); + $expectedResponse->setDescription($description); + $expectedResponse->setEnableStackdriverLogging($enableStackdriverLogging); + $expectedResponse->setEnableStackdriverMonitoring($enableStackdriverMonitoring); + $expectedResponse->setPrivateInstance($privateInstance); + $expectedResponse->setStateMessage($stateMessage); + $expectedResponse->setServiceEndpoint($serviceEndpoint); + $expectedResponse->setZone($zone); + $expectedResponse->setVersion($version); + $expectedResponse->setServiceAccount($serviceAccount); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setApiEndpoint($apiEndpoint); + $expectedResponse->setGcsBucket($gcsBucket); + $expectedResponse->setP4ServiceAccount($p4ServiceAccount); + $expectedResponse->setTenantProjectId($tenantProjectId); + $expectedResponse->setDataprocServiceAccount($dataprocServiceAccount); + $expectedResponse->setEnableRbac($enableRbac); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->instanceName('[PROJECT]', '[LOCATION]', '[INSTANCE]'); + $request = (new GetInstanceRequest()) + ->setName($formattedName); + $response = $gapicClient->getInstance($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datafusion.v1.DataFusion/GetInstance', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getInstanceExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->instanceName('[PROJECT]', '[LOCATION]', '[INSTANCE]'); + $request = (new GetInstanceRequest()) + ->setName($formattedName); + try { + $gapicClient->getInstance($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listAvailableVersionsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $availableVersionsElement = new Version(); + $availableVersions = [ + $availableVersionsElement, + ]; + $expectedResponse = new ListAvailableVersionsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setAvailableVersions($availableVersions); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListAvailableVersionsRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listAvailableVersions($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getAvailableVersions()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datafusion.v1.DataFusion/ListAvailableVersions', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listAvailableVersionsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListAvailableVersionsRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listAvailableVersions($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listInstancesTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $instancesElement = new Instance(); + $instances = [ + $instancesElement, + ]; + $expectedResponse = new ListInstancesResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setInstances($instances); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListInstancesRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listInstances($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getInstances()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datafusion.v1.DataFusion/ListInstances', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listInstancesExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListInstancesRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listInstances($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function restartInstanceTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/restartInstanceTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name2 = 'name2-1052831874'; + $description = 'description-1724546052'; + $enableStackdriverLogging = true; + $enableStackdriverMonitoring = false; + $privateInstance = false; + $stateMessage = 'stateMessage29641305'; + $serviceEndpoint = 'serviceEndpoint-676052001'; + $zone = 'zone3744684'; + $version = 'version351608024'; + $serviceAccount = 'serviceAccount-1948028253'; + $displayName = 'displayName1615086568'; + $apiEndpoint = 'apiEndpoint-1381395942'; + $gcsBucket = 'gcsBucket-1720393710'; + $p4ServiceAccount = 'p4ServiceAccount-1554461144'; + $tenantProjectId = 'tenantProjectId-2129337674'; + $dataprocServiceAccount = 'dataprocServiceAccount-493324700'; + $enableRbac = true; + $expectedResponse = new Instance(); + $expectedResponse->setName($name2); + $expectedResponse->setDescription($description); + $expectedResponse->setEnableStackdriverLogging($enableStackdriverLogging); + $expectedResponse->setEnableStackdriverMonitoring($enableStackdriverMonitoring); + $expectedResponse->setPrivateInstance($privateInstance); + $expectedResponse->setStateMessage($stateMessage); + $expectedResponse->setServiceEndpoint($serviceEndpoint); + $expectedResponse->setZone($zone); + $expectedResponse->setVersion($version); + $expectedResponse->setServiceAccount($serviceAccount); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setApiEndpoint($apiEndpoint); + $expectedResponse->setGcsBucket($gcsBucket); + $expectedResponse->setP4ServiceAccount($p4ServiceAccount); + $expectedResponse->setTenantProjectId($tenantProjectId); + $expectedResponse->setDataprocServiceAccount($dataprocServiceAccount); + $expectedResponse->setEnableRbac($enableRbac); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/restartInstanceTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->instanceName('[PROJECT]', '[LOCATION]', '[INSTANCE]'); + $request = (new RestartInstanceRequest()) + ->setName($formattedName); + $response = $gapicClient->restartInstance($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datafusion.v1.DataFusion/RestartInstance', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/restartInstanceTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function restartInstanceExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/restartInstanceTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->instanceName('[PROJECT]', '[LOCATION]', '[INSTANCE]'); + $request = (new RestartInstanceRequest()) + ->setName($formattedName); + $response = $gapicClient->restartInstance($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/restartInstanceTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function updateInstanceTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/updateInstanceTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $description = 'description-1724546052'; + $enableStackdriverLogging = true; + $enableStackdriverMonitoring = false; + $privateInstance = false; + $stateMessage = 'stateMessage29641305'; + $serviceEndpoint = 'serviceEndpoint-676052001'; + $zone = 'zone3744684'; + $version = 'version351608024'; + $serviceAccount = 'serviceAccount-1948028253'; + $displayName = 'displayName1615086568'; + $apiEndpoint = 'apiEndpoint-1381395942'; + $gcsBucket = 'gcsBucket-1720393710'; + $p4ServiceAccount = 'p4ServiceAccount-1554461144'; + $tenantProjectId = 'tenantProjectId-2129337674'; + $dataprocServiceAccount = 'dataprocServiceAccount-493324700'; + $enableRbac = true; + $expectedResponse = new Instance(); + $expectedResponse->setName($name); + $expectedResponse->setDescription($description); + $expectedResponse->setEnableStackdriverLogging($enableStackdriverLogging); + $expectedResponse->setEnableStackdriverMonitoring($enableStackdriverMonitoring); + $expectedResponse->setPrivateInstance($privateInstance); + $expectedResponse->setStateMessage($stateMessage); + $expectedResponse->setServiceEndpoint($serviceEndpoint); + $expectedResponse->setZone($zone); + $expectedResponse->setVersion($version); + $expectedResponse->setServiceAccount($serviceAccount); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setApiEndpoint($apiEndpoint); + $expectedResponse->setGcsBucket($gcsBucket); + $expectedResponse->setP4ServiceAccount($p4ServiceAccount); + $expectedResponse->setTenantProjectId($tenantProjectId); + $expectedResponse->setDataprocServiceAccount($dataprocServiceAccount); + $expectedResponse->setEnableRbac($enableRbac); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/updateInstanceTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $instance = new Instance(); + $instanceType = Type::TYPE_UNSPECIFIED; + $instance->setType($instanceType); + $request = (new UpdateInstanceRequest()) + ->setInstance($instance); + $response = $gapicClient->updateInstance($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datafusion.v1.DataFusion/UpdateInstance', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getInstance(); + $this->assertProtobufEquals($instance, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateInstanceTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function updateInstanceExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/updateInstanceTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $instance = new Instance(); + $instanceType = Type::TYPE_UNSPECIFIED; + $instance->setType($instanceType); + $request = (new UpdateInstanceRequest()) + ->setInstance($instance); + $response = $gapicClient->updateInstance($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateInstanceTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function createInstanceAsyncTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/createInstanceTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $description = 'description-1724546052'; + $enableStackdriverLogging = true; + $enableStackdriverMonitoring = false; + $privateInstance = false; + $stateMessage = 'stateMessage29641305'; + $serviceEndpoint = 'serviceEndpoint-676052001'; + $zone = 'zone3744684'; + $version = 'version351608024'; + $serviceAccount = 'serviceAccount-1948028253'; + $displayName = 'displayName1615086568'; + $apiEndpoint = 'apiEndpoint-1381395942'; + $gcsBucket = 'gcsBucket-1720393710'; + $p4ServiceAccount = 'p4ServiceAccount-1554461144'; + $tenantProjectId = 'tenantProjectId-2129337674'; + $dataprocServiceAccount = 'dataprocServiceAccount-493324700'; + $enableRbac = true; + $expectedResponse = new Instance(); + $expectedResponse->setName($name); + $expectedResponse->setDescription($description); + $expectedResponse->setEnableStackdriverLogging($enableStackdriverLogging); + $expectedResponse->setEnableStackdriverMonitoring($enableStackdriverMonitoring); + $expectedResponse->setPrivateInstance($privateInstance); + $expectedResponse->setStateMessage($stateMessage); + $expectedResponse->setServiceEndpoint($serviceEndpoint); + $expectedResponse->setZone($zone); + $expectedResponse->setVersion($version); + $expectedResponse->setServiceAccount($serviceAccount); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setApiEndpoint($apiEndpoint); + $expectedResponse->setGcsBucket($gcsBucket); + $expectedResponse->setP4ServiceAccount($p4ServiceAccount); + $expectedResponse->setTenantProjectId($tenantProjectId); + $expectedResponse->setDataprocServiceAccount($dataprocServiceAccount); + $expectedResponse->setEnableRbac($enableRbac); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createInstanceTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $instanceId = 'instanceId-2101995259'; + $request = (new CreateInstanceRequest()) + ->setParent($formattedParent) + ->setInstanceId($instanceId); + $response = $gapicClient->createInstanceAsync($request)->wait(); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datafusion.v1.DataFusion/CreateInstance', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getInstanceId(); + $this->assertProtobufEquals($instanceId, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createInstanceTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } +} diff --git a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/create_annotation_spec_set.php b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/create_annotation_spec_set.php index af3db47e9c37..25694461f1cf 100644 --- a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/create_annotation_spec_set.php +++ b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/create_annotation_spec_set.php @@ -25,7 +25,8 @@ // [START datalabeling_v1beta1_generated_DataLabelingService_CreateAnnotationSpecSet_sync] use Google\ApiCore\ApiException; use Google\Cloud\DataLabeling\V1beta1\AnnotationSpecSet; -use Google\Cloud\DataLabeling\V1beta1\DataLabelingServiceClient; +use Google\Cloud\DataLabeling\V1beta1\Client\DataLabelingServiceClient; +use Google\Cloud\DataLabeling\V1beta1\CreateAnnotationSpecSetRequest; /** * Creates an annotation spec set by providing a set of labels. @@ -39,16 +40,16 @@ function create_annotation_spec_set_sample(string $formattedParent): void // Create a client. $dataLabelingServiceClient = new DataLabelingServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $annotationSpecSet = new AnnotationSpecSet(); + $request = (new CreateAnnotationSpecSetRequest()) + ->setParent($formattedParent) + ->setAnnotationSpecSet($annotationSpecSet); // Call the API and handle any network failures. try { /** @var AnnotationSpecSet $response */ - $response = $dataLabelingServiceClient->createAnnotationSpecSet( - $formattedParent, - $annotationSpecSet - ); + $response = $dataLabelingServiceClient->createAnnotationSpecSet($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/create_dataset.php b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/create_dataset.php index 1f933747a2df..72d7632f70ec 100644 --- a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/create_dataset.php +++ b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/create_dataset.php @@ -24,7 +24,8 @@ // [START datalabeling_v1beta1_generated_DataLabelingService_CreateDataset_sync] use Google\ApiCore\ApiException; -use Google\Cloud\DataLabeling\V1beta1\DataLabelingServiceClient; +use Google\Cloud\DataLabeling\V1beta1\Client\DataLabelingServiceClient; +use Google\Cloud\DataLabeling\V1beta1\CreateDatasetRequest; use Google\Cloud\DataLabeling\V1beta1\Dataset; /** @@ -39,13 +40,16 @@ function create_dataset_sample(string $formattedParent): void // Create a client. $dataLabelingServiceClient = new DataLabelingServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $dataset = new Dataset(); + $request = (new CreateDatasetRequest()) + ->setParent($formattedParent) + ->setDataset($dataset); // Call the API and handle any network failures. try { /** @var Dataset $response */ - $response = $dataLabelingServiceClient->createDataset($formattedParent, $dataset); + $response = $dataLabelingServiceClient->createDataset($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/create_evaluation_job.php b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/create_evaluation_job.php index e4bd52295345..07c97cdf4174 100644 --- a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/create_evaluation_job.php +++ b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/create_evaluation_job.php @@ -24,7 +24,8 @@ // [START datalabeling_v1beta1_generated_DataLabelingService_CreateEvaluationJob_sync] use Google\ApiCore\ApiException; -use Google\Cloud\DataLabeling\V1beta1\DataLabelingServiceClient; +use Google\Cloud\DataLabeling\V1beta1\Client\DataLabelingServiceClient; +use Google\Cloud\DataLabeling\V1beta1\CreateEvaluationJobRequest; use Google\Cloud\DataLabeling\V1beta1\EvaluationJob; /** @@ -39,13 +40,16 @@ function create_evaluation_job_sample(string $formattedParent): void // Create a client. $dataLabelingServiceClient = new DataLabelingServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $job = new EvaluationJob(); + $request = (new CreateEvaluationJobRequest()) + ->setParent($formattedParent) + ->setJob($job); // Call the API and handle any network failures. try { /** @var EvaluationJob $response */ - $response = $dataLabelingServiceClient->createEvaluationJob($formattedParent, $job); + $response = $dataLabelingServiceClient->createEvaluationJob($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/create_instruction.php b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/create_instruction.php index 4426e3b0a548..c2e0b473cda0 100644 --- a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/create_instruction.php +++ b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/create_instruction.php @@ -25,7 +25,8 @@ // [START datalabeling_v1beta1_generated_DataLabelingService_CreateInstruction_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\DataLabeling\V1beta1\DataLabelingServiceClient; +use Google\Cloud\DataLabeling\V1beta1\Client\DataLabelingServiceClient; +use Google\Cloud\DataLabeling\V1beta1\CreateInstructionRequest; use Google\Cloud\DataLabeling\V1beta1\Instruction; use Google\Rpc\Status; @@ -41,13 +42,16 @@ function create_instruction_sample(string $formattedParent): void // Create a client. $dataLabelingServiceClient = new DataLabelingServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $instruction = new Instruction(); + $request = (new CreateInstructionRequest()) + ->setParent($formattedParent) + ->setInstruction($instruction); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $dataLabelingServiceClient->createInstruction($formattedParent, $instruction); + $response = $dataLabelingServiceClient->createInstruction($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/delete_annotated_dataset.php b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/delete_annotated_dataset.php index b1e1edb02990..75368b264fc7 100644 --- a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/delete_annotated_dataset.php +++ b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/delete_annotated_dataset.php @@ -24,7 +24,8 @@ // [START datalabeling_v1beta1_generated_DataLabelingService_DeleteAnnotatedDataset_sync] use Google\ApiCore\ApiException; -use Google\Cloud\DataLabeling\V1beta1\DataLabelingServiceClient; +use Google\Cloud\DataLabeling\V1beta1\Client\DataLabelingServiceClient; +use Google\Cloud\DataLabeling\V1beta1\DeleteAnnotatedDatasetRequest; /** * Deletes an annotated dataset by resource name. @@ -39,9 +40,13 @@ function delete_annotated_dataset_sample(string $formattedName): void // Create a client. $dataLabelingServiceClient = new DataLabelingServiceClient(); + // Prepare the request message. + $request = (new DeleteAnnotatedDatasetRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { - $dataLabelingServiceClient->deleteAnnotatedDataset($formattedName); + $dataLabelingServiceClient->deleteAnnotatedDataset($request); printf('Call completed successfully.' . PHP_EOL); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/delete_annotation_spec_set.php b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/delete_annotation_spec_set.php index 04c50e232245..806a3fe59b39 100644 --- a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/delete_annotation_spec_set.php +++ b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/delete_annotation_spec_set.php @@ -24,7 +24,8 @@ // [START datalabeling_v1beta1_generated_DataLabelingService_DeleteAnnotationSpecSet_sync] use Google\ApiCore\ApiException; -use Google\Cloud\DataLabeling\V1beta1\DataLabelingServiceClient; +use Google\Cloud\DataLabeling\V1beta1\Client\DataLabelingServiceClient; +use Google\Cloud\DataLabeling\V1beta1\DeleteAnnotationSpecSetRequest; /** * Deletes an annotation spec set by resource name. @@ -38,9 +39,13 @@ function delete_annotation_spec_set_sample(string $formattedName): void // Create a client. $dataLabelingServiceClient = new DataLabelingServiceClient(); + // Prepare the request message. + $request = (new DeleteAnnotationSpecSetRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { - $dataLabelingServiceClient->deleteAnnotationSpecSet($formattedName); + $dataLabelingServiceClient->deleteAnnotationSpecSet($request); printf('Call completed successfully.' . PHP_EOL); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/delete_dataset.php b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/delete_dataset.php index 7132b70ddaa8..bb62cb2f0405 100644 --- a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/delete_dataset.php +++ b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/delete_dataset.php @@ -24,7 +24,8 @@ // [START datalabeling_v1beta1_generated_DataLabelingService_DeleteDataset_sync] use Google\ApiCore\ApiException; -use Google\Cloud\DataLabeling\V1beta1\DataLabelingServiceClient; +use Google\Cloud\DataLabeling\V1beta1\Client\DataLabelingServiceClient; +use Google\Cloud\DataLabeling\V1beta1\DeleteDatasetRequest; /** * Deletes a dataset by resource name. @@ -38,9 +39,13 @@ function delete_dataset_sample(string $formattedName): void // Create a client. $dataLabelingServiceClient = new DataLabelingServiceClient(); + // Prepare the request message. + $request = (new DeleteDatasetRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { - $dataLabelingServiceClient->deleteDataset($formattedName); + $dataLabelingServiceClient->deleteDataset($request); printf('Call completed successfully.' . PHP_EOL); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/delete_evaluation_job.php b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/delete_evaluation_job.php index c537dd2345c4..d979fbf00b92 100644 --- a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/delete_evaluation_job.php +++ b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/delete_evaluation_job.php @@ -24,7 +24,8 @@ // [START datalabeling_v1beta1_generated_DataLabelingService_DeleteEvaluationJob_sync] use Google\ApiCore\ApiException; -use Google\Cloud\DataLabeling\V1beta1\DataLabelingServiceClient; +use Google\Cloud\DataLabeling\V1beta1\Client\DataLabelingServiceClient; +use Google\Cloud\DataLabeling\V1beta1\DeleteEvaluationJobRequest; /** * Stops and deletes an evaluation job. @@ -39,9 +40,13 @@ function delete_evaluation_job_sample(string $formattedName): void // Create a client. $dataLabelingServiceClient = new DataLabelingServiceClient(); + // Prepare the request message. + $request = (new DeleteEvaluationJobRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { - $dataLabelingServiceClient->deleteEvaluationJob($formattedName); + $dataLabelingServiceClient->deleteEvaluationJob($request); printf('Call completed successfully.' . PHP_EOL); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/delete_instruction.php b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/delete_instruction.php index c24831ee4de9..aed96c7901a7 100644 --- a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/delete_instruction.php +++ b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/delete_instruction.php @@ -24,7 +24,8 @@ // [START datalabeling_v1beta1_generated_DataLabelingService_DeleteInstruction_sync] use Google\ApiCore\ApiException; -use Google\Cloud\DataLabeling\V1beta1\DataLabelingServiceClient; +use Google\Cloud\DataLabeling\V1beta1\Client\DataLabelingServiceClient; +use Google\Cloud\DataLabeling\V1beta1\DeleteInstructionRequest; /** * Deletes an instruction object by resource name. @@ -38,9 +39,13 @@ function delete_instruction_sample(string $formattedName): void // Create a client. $dataLabelingServiceClient = new DataLabelingServiceClient(); + // Prepare the request message. + $request = (new DeleteInstructionRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { - $dataLabelingServiceClient->deleteInstruction($formattedName); + $dataLabelingServiceClient->deleteInstruction($request); printf('Call completed successfully.' . PHP_EOL); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/export_data.php b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/export_data.php index 01cf46e1f7ac..36a2d14b6420 100644 --- a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/export_data.php +++ b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/export_data.php @@ -25,8 +25,9 @@ // [START datalabeling_v1beta1_generated_DataLabelingService_ExportData_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\DataLabeling\V1beta1\DataLabelingServiceClient; +use Google\Cloud\DataLabeling\V1beta1\Client\DataLabelingServiceClient; use Google\Cloud\DataLabeling\V1beta1\ExportDataOperationResponse; +use Google\Cloud\DataLabeling\V1beta1\ExportDataRequest; use Google\Cloud\DataLabeling\V1beta1\OutputConfig; use Google\Rpc\Status; @@ -48,17 +49,17 @@ function export_data_sample(string $formattedName, string $formattedAnnotatedDat // Create a client. $dataLabelingServiceClient = new DataLabelingServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $outputConfig = new OutputConfig(); + $request = (new ExportDataRequest()) + ->setName($formattedName) + ->setAnnotatedDataset($formattedAnnotatedDataset) + ->setOutputConfig($outputConfig); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $dataLabelingServiceClient->exportData( - $formattedName, - $formattedAnnotatedDataset, - $outputConfig - ); + $response = $dataLabelingServiceClient->exportData($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/get_annotated_dataset.php b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/get_annotated_dataset.php index efec30d05cc7..450abfa3bca5 100644 --- a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/get_annotated_dataset.php +++ b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/get_annotated_dataset.php @@ -25,7 +25,8 @@ // [START datalabeling_v1beta1_generated_DataLabelingService_GetAnnotatedDataset_sync] use Google\ApiCore\ApiException; use Google\Cloud\DataLabeling\V1beta1\AnnotatedDataset; -use Google\Cloud\DataLabeling\V1beta1\DataLabelingServiceClient; +use Google\Cloud\DataLabeling\V1beta1\Client\DataLabelingServiceClient; +use Google\Cloud\DataLabeling\V1beta1\GetAnnotatedDatasetRequest; /** * Gets an annotated dataset by resource name. @@ -40,10 +41,14 @@ function get_annotated_dataset_sample(string $formattedName): void // Create a client. $dataLabelingServiceClient = new DataLabelingServiceClient(); + // Prepare the request message. + $request = (new GetAnnotatedDatasetRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var AnnotatedDataset $response */ - $response = $dataLabelingServiceClient->getAnnotatedDataset($formattedName); + $response = $dataLabelingServiceClient->getAnnotatedDataset($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/get_annotation_spec_set.php b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/get_annotation_spec_set.php index 298fe3bc0d02..2884f35f5046 100644 --- a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/get_annotation_spec_set.php +++ b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/get_annotation_spec_set.php @@ -25,7 +25,8 @@ // [START datalabeling_v1beta1_generated_DataLabelingService_GetAnnotationSpecSet_sync] use Google\ApiCore\ApiException; use Google\Cloud\DataLabeling\V1beta1\AnnotationSpecSet; -use Google\Cloud\DataLabeling\V1beta1\DataLabelingServiceClient; +use Google\Cloud\DataLabeling\V1beta1\Client\DataLabelingServiceClient; +use Google\Cloud\DataLabeling\V1beta1\GetAnnotationSpecSetRequest; /** * Gets an annotation spec set by resource name. @@ -39,10 +40,14 @@ function get_annotation_spec_set_sample(string $formattedName): void // Create a client. $dataLabelingServiceClient = new DataLabelingServiceClient(); + // Prepare the request message. + $request = (new GetAnnotationSpecSetRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var AnnotationSpecSet $response */ - $response = $dataLabelingServiceClient->getAnnotationSpecSet($formattedName); + $response = $dataLabelingServiceClient->getAnnotationSpecSet($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/get_data_item.php b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/get_data_item.php index eb7aa137d9cb..ab04c193cf1b 100644 --- a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/get_data_item.php +++ b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/get_data_item.php @@ -24,8 +24,9 @@ // [START datalabeling_v1beta1_generated_DataLabelingService_GetDataItem_sync] use Google\ApiCore\ApiException; +use Google\Cloud\DataLabeling\V1beta1\Client\DataLabelingServiceClient; use Google\Cloud\DataLabeling\V1beta1\DataItem; -use Google\Cloud\DataLabeling\V1beta1\DataLabelingServiceClient; +use Google\Cloud\DataLabeling\V1beta1\GetDataItemRequest; /** * Gets a data item in a dataset by resource name. This API can be @@ -40,10 +41,14 @@ function get_data_item_sample(string $formattedName): void // Create a client. $dataLabelingServiceClient = new DataLabelingServiceClient(); + // Prepare the request message. + $request = (new GetDataItemRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var DataItem $response */ - $response = $dataLabelingServiceClient->getDataItem($formattedName); + $response = $dataLabelingServiceClient->getDataItem($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/get_dataset.php b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/get_dataset.php index 46274ae1b7c3..86c982129372 100644 --- a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/get_dataset.php +++ b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/get_dataset.php @@ -24,8 +24,9 @@ // [START datalabeling_v1beta1_generated_DataLabelingService_GetDataset_sync] use Google\ApiCore\ApiException; -use Google\Cloud\DataLabeling\V1beta1\DataLabelingServiceClient; +use Google\Cloud\DataLabeling\V1beta1\Client\DataLabelingServiceClient; use Google\Cloud\DataLabeling\V1beta1\Dataset; +use Google\Cloud\DataLabeling\V1beta1\GetDatasetRequest; /** * Gets dataset by resource name. @@ -39,10 +40,14 @@ function get_dataset_sample(string $formattedName): void // Create a client. $dataLabelingServiceClient = new DataLabelingServiceClient(); + // Prepare the request message. + $request = (new GetDatasetRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var Dataset $response */ - $response = $dataLabelingServiceClient->getDataset($formattedName); + $response = $dataLabelingServiceClient->getDataset($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/get_evaluation.php b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/get_evaluation.php index a224f5201868..52eb7b9af8d9 100644 --- a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/get_evaluation.php +++ b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/get_evaluation.php @@ -24,8 +24,9 @@ // [START datalabeling_v1beta1_generated_DataLabelingService_GetEvaluation_sync] use Google\ApiCore\ApiException; -use Google\Cloud\DataLabeling\V1beta1\DataLabelingServiceClient; +use Google\Cloud\DataLabeling\V1beta1\Client\DataLabelingServiceClient; use Google\Cloud\DataLabeling\V1beta1\Evaluation; +use Google\Cloud\DataLabeling\V1beta1\GetEvaluationRequest; /** * Gets an evaluation by resource name (to search, use @@ -41,10 +42,14 @@ function get_evaluation_sample(string $formattedName): void // Create a client. $dataLabelingServiceClient = new DataLabelingServiceClient(); + // Prepare the request message. + $request = (new GetEvaluationRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var Evaluation $response */ - $response = $dataLabelingServiceClient->getEvaluation($formattedName); + $response = $dataLabelingServiceClient->getEvaluation($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/get_evaluation_job.php b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/get_evaluation_job.php index b869b0eaa978..05a7a7c85481 100644 --- a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/get_evaluation_job.php +++ b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/get_evaluation_job.php @@ -24,8 +24,9 @@ // [START datalabeling_v1beta1_generated_DataLabelingService_GetEvaluationJob_sync] use Google\ApiCore\ApiException; -use Google\Cloud\DataLabeling\V1beta1\DataLabelingServiceClient; +use Google\Cloud\DataLabeling\V1beta1\Client\DataLabelingServiceClient; use Google\Cloud\DataLabeling\V1beta1\EvaluationJob; +use Google\Cloud\DataLabeling\V1beta1\GetEvaluationJobRequest; /** * Gets an evaluation job by resource name. @@ -40,10 +41,14 @@ function get_evaluation_job_sample(string $formattedName): void // Create a client. $dataLabelingServiceClient = new DataLabelingServiceClient(); + // Prepare the request message. + $request = (new GetEvaluationJobRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var EvaluationJob $response */ - $response = $dataLabelingServiceClient->getEvaluationJob($formattedName); + $response = $dataLabelingServiceClient->getEvaluationJob($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/get_example.php b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/get_example.php index c07ec5bfbe51..8cf3985102bf 100644 --- a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/get_example.php +++ b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/get_example.php @@ -24,8 +24,9 @@ // [START datalabeling_v1beta1_generated_DataLabelingService_GetExample_sync] use Google\ApiCore\ApiException; -use Google\Cloud\DataLabeling\V1beta1\DataLabelingServiceClient; +use Google\Cloud\DataLabeling\V1beta1\Client\DataLabelingServiceClient; use Google\Cloud\DataLabeling\V1beta1\Example; +use Google\Cloud\DataLabeling\V1beta1\GetExampleRequest; /** * Gets an example by resource name, including both data and annotation. @@ -40,10 +41,14 @@ function get_example_sample(string $formattedName): void // Create a client. $dataLabelingServiceClient = new DataLabelingServiceClient(); + // Prepare the request message. + $request = (new GetExampleRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var Example $response */ - $response = $dataLabelingServiceClient->getExample($formattedName); + $response = $dataLabelingServiceClient->getExample($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/get_instruction.php b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/get_instruction.php index ae8866963bdd..1d46ce14ed3a 100644 --- a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/get_instruction.php +++ b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/get_instruction.php @@ -24,7 +24,8 @@ // [START datalabeling_v1beta1_generated_DataLabelingService_GetInstruction_sync] use Google\ApiCore\ApiException; -use Google\Cloud\DataLabeling\V1beta1\DataLabelingServiceClient; +use Google\Cloud\DataLabeling\V1beta1\Client\DataLabelingServiceClient; +use Google\Cloud\DataLabeling\V1beta1\GetInstructionRequest; use Google\Cloud\DataLabeling\V1beta1\Instruction; /** @@ -39,10 +40,14 @@ function get_instruction_sample(string $formattedName): void // Create a client. $dataLabelingServiceClient = new DataLabelingServiceClient(); + // Prepare the request message. + $request = (new GetInstructionRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var Instruction $response */ - $response = $dataLabelingServiceClient->getInstruction($formattedName); + $response = $dataLabelingServiceClient->getInstruction($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/import_data.php b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/import_data.php index dbac5efbd5d4..71d654495507 100644 --- a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/import_data.php +++ b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/import_data.php @@ -25,8 +25,9 @@ // [START datalabeling_v1beta1_generated_DataLabelingService_ImportData_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\DataLabeling\V1beta1\DataLabelingServiceClient; +use Google\Cloud\DataLabeling\V1beta1\Client\DataLabelingServiceClient; use Google\Cloud\DataLabeling\V1beta1\ImportDataOperationResponse; +use Google\Cloud\DataLabeling\V1beta1\ImportDataRequest; use Google\Cloud\DataLabeling\V1beta1\InputConfig; use Google\Rpc\Status; @@ -46,13 +47,16 @@ function import_data_sample(string $formattedName): void // Create a client. $dataLabelingServiceClient = new DataLabelingServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $inputConfig = new InputConfig(); + $request = (new ImportDataRequest()) + ->setName($formattedName) + ->setInputConfig($inputConfig); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $dataLabelingServiceClient->importData($formattedName, $inputConfig); + $response = $dataLabelingServiceClient->importData($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/label_image.php b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/label_image.php index 4e4a81b1dc61..cd4427c56edf 100644 --- a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/label_image.php +++ b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/label_image.php @@ -26,8 +26,9 @@ use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; use Google\Cloud\DataLabeling\V1beta1\AnnotatedDataset; -use Google\Cloud\DataLabeling\V1beta1\DataLabelingServiceClient; +use Google\Cloud\DataLabeling\V1beta1\Client\DataLabelingServiceClient; use Google\Cloud\DataLabeling\V1beta1\HumanAnnotationConfig; +use Google\Cloud\DataLabeling\V1beta1\LabelImageRequest; use Google\Cloud\DataLabeling\V1beta1\LabelImageRequest\Feature; use Google\Rpc\Status; @@ -53,15 +54,19 @@ function label_image_sample( // Create a client. $dataLabelingServiceClient = new DataLabelingServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $basicConfig = (new HumanAnnotationConfig()) ->setInstruction($basicConfigInstruction) ->setAnnotatedDatasetDisplayName($basicConfigAnnotatedDatasetDisplayName); + $request = (new LabelImageRequest()) + ->setParent($formattedParent) + ->setBasicConfig($basicConfig) + ->setFeature($feature); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $dataLabelingServiceClient->labelImage($formattedParent, $basicConfig, $feature); + $response = $dataLabelingServiceClient->labelImage($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/label_text.php b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/label_text.php index f86fe6da1ca1..d9217cfd4f37 100644 --- a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/label_text.php +++ b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/label_text.php @@ -26,8 +26,9 @@ use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; use Google\Cloud\DataLabeling\V1beta1\AnnotatedDataset; -use Google\Cloud\DataLabeling\V1beta1\DataLabelingServiceClient; +use Google\Cloud\DataLabeling\V1beta1\Client\DataLabelingServiceClient; use Google\Cloud\DataLabeling\V1beta1\HumanAnnotationConfig; +use Google\Cloud\DataLabeling\V1beta1\LabelTextRequest; use Google\Cloud\DataLabeling\V1beta1\LabelTextRequest\Feature; use Google\Rpc\Status; @@ -53,15 +54,19 @@ function label_text_sample( // Create a client. $dataLabelingServiceClient = new DataLabelingServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $basicConfig = (new HumanAnnotationConfig()) ->setInstruction($basicConfigInstruction) ->setAnnotatedDatasetDisplayName($basicConfigAnnotatedDatasetDisplayName); + $request = (new LabelTextRequest()) + ->setParent($formattedParent) + ->setBasicConfig($basicConfig) + ->setFeature($feature); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $dataLabelingServiceClient->labelText($formattedParent, $basicConfig, $feature); + $response = $dataLabelingServiceClient->labelText($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/label_video.php b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/label_video.php index 15f3fb6d48a1..918b1ee22c91 100644 --- a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/label_video.php +++ b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/label_video.php @@ -26,8 +26,9 @@ use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; use Google\Cloud\DataLabeling\V1beta1\AnnotatedDataset; -use Google\Cloud\DataLabeling\V1beta1\DataLabelingServiceClient; +use Google\Cloud\DataLabeling\V1beta1\Client\DataLabelingServiceClient; use Google\Cloud\DataLabeling\V1beta1\HumanAnnotationConfig; +use Google\Cloud\DataLabeling\V1beta1\LabelVideoRequest; use Google\Cloud\DataLabeling\V1beta1\LabelVideoRequest\Feature; use Google\Rpc\Status; @@ -53,15 +54,19 @@ function label_video_sample( // Create a client. $dataLabelingServiceClient = new DataLabelingServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $basicConfig = (new HumanAnnotationConfig()) ->setInstruction($basicConfigInstruction) ->setAnnotatedDatasetDisplayName($basicConfigAnnotatedDatasetDisplayName); + $request = (new LabelVideoRequest()) + ->setParent($formattedParent) + ->setBasicConfig($basicConfig) + ->setFeature($feature); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $dataLabelingServiceClient->labelVideo($formattedParent, $basicConfig, $feature); + $response = $dataLabelingServiceClient->labelVideo($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/list_annotated_datasets.php b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/list_annotated_datasets.php index 74ab27c8f908..626a39520506 100644 --- a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/list_annotated_datasets.php +++ b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/list_annotated_datasets.php @@ -26,7 +26,8 @@ use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; use Google\Cloud\DataLabeling\V1beta1\AnnotatedDataset; -use Google\Cloud\DataLabeling\V1beta1\DataLabelingServiceClient; +use Google\Cloud\DataLabeling\V1beta1\Client\DataLabelingServiceClient; +use Google\Cloud\DataLabeling\V1beta1\ListAnnotatedDatasetsRequest; /** * Lists annotated datasets for a dataset. Pagination is supported. @@ -40,10 +41,14 @@ function list_annotated_datasets_sample(string $formattedParent): void // Create a client. $dataLabelingServiceClient = new DataLabelingServiceClient(); + // Prepare the request message. + $request = (new ListAnnotatedDatasetsRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $dataLabelingServiceClient->listAnnotatedDatasets($formattedParent); + $response = $dataLabelingServiceClient->listAnnotatedDatasets($request); /** @var AnnotatedDataset $element */ foreach ($response as $element) { diff --git a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/list_annotation_spec_sets.php b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/list_annotation_spec_sets.php index 6f39d820fae3..2fd5ef4f69c1 100644 --- a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/list_annotation_spec_sets.php +++ b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/list_annotation_spec_sets.php @@ -26,7 +26,8 @@ use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; use Google\Cloud\DataLabeling\V1beta1\AnnotationSpecSet; -use Google\Cloud\DataLabeling\V1beta1\DataLabelingServiceClient; +use Google\Cloud\DataLabeling\V1beta1\Client\DataLabelingServiceClient; +use Google\Cloud\DataLabeling\V1beta1\ListAnnotationSpecSetsRequest; /** * Lists annotation spec sets for a project. Pagination is supported. @@ -40,10 +41,14 @@ function list_annotation_spec_sets_sample(string $formattedParent): void // Create a client. $dataLabelingServiceClient = new DataLabelingServiceClient(); + // Prepare the request message. + $request = (new ListAnnotationSpecSetsRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $dataLabelingServiceClient->listAnnotationSpecSets($formattedParent); + $response = $dataLabelingServiceClient->listAnnotationSpecSets($request); /** @var AnnotationSpecSet $element */ foreach ($response as $element) { diff --git a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/list_data_items.php b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/list_data_items.php index ac3b5f5ccf64..00ac1495230e 100644 --- a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/list_data_items.php +++ b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/list_data_items.php @@ -25,8 +25,9 @@ // [START datalabeling_v1beta1_generated_DataLabelingService_ListDataItems_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; +use Google\Cloud\DataLabeling\V1beta1\Client\DataLabelingServiceClient; use Google\Cloud\DataLabeling\V1beta1\DataItem; -use Google\Cloud\DataLabeling\V1beta1\DataLabelingServiceClient; +use Google\Cloud\DataLabeling\V1beta1\ListDataItemsRequest; /** * Lists data items in a dataset. This API can be called after data @@ -41,10 +42,14 @@ function list_data_items_sample(string $formattedParent): void // Create a client. $dataLabelingServiceClient = new DataLabelingServiceClient(); + // Prepare the request message. + $request = (new ListDataItemsRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $dataLabelingServiceClient->listDataItems($formattedParent); + $response = $dataLabelingServiceClient->listDataItems($request); /** @var DataItem $element */ foreach ($response as $element) { diff --git a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/list_datasets.php b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/list_datasets.php index ed74d4cbd450..043c689e598c 100644 --- a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/list_datasets.php +++ b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/list_datasets.php @@ -25,8 +25,9 @@ // [START datalabeling_v1beta1_generated_DataLabelingService_ListDatasets_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; -use Google\Cloud\DataLabeling\V1beta1\DataLabelingServiceClient; +use Google\Cloud\DataLabeling\V1beta1\Client\DataLabelingServiceClient; use Google\Cloud\DataLabeling\V1beta1\Dataset; +use Google\Cloud\DataLabeling\V1beta1\ListDatasetsRequest; /** * Lists datasets under a project. Pagination is supported. @@ -40,10 +41,14 @@ function list_datasets_sample(string $formattedParent): void // Create a client. $dataLabelingServiceClient = new DataLabelingServiceClient(); + // Prepare the request message. + $request = (new ListDatasetsRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $dataLabelingServiceClient->listDatasets($formattedParent); + $response = $dataLabelingServiceClient->listDatasets($request); /** @var Dataset $element */ foreach ($response as $element) { diff --git a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/list_evaluation_jobs.php b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/list_evaluation_jobs.php index 4e97685c38c3..e2b7147b8335 100644 --- a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/list_evaluation_jobs.php +++ b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/list_evaluation_jobs.php @@ -25,8 +25,9 @@ // [START datalabeling_v1beta1_generated_DataLabelingService_ListEvaluationJobs_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; -use Google\Cloud\DataLabeling\V1beta1\DataLabelingServiceClient; +use Google\Cloud\DataLabeling\V1beta1\Client\DataLabelingServiceClient; use Google\Cloud\DataLabeling\V1beta1\EvaluationJob; +use Google\Cloud\DataLabeling\V1beta1\ListEvaluationJobsRequest; /** * Lists all evaluation jobs within a project with possible filters. @@ -41,10 +42,14 @@ function list_evaluation_jobs_sample(string $formattedParent): void // Create a client. $dataLabelingServiceClient = new DataLabelingServiceClient(); + // Prepare the request message. + $request = (new ListEvaluationJobsRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $dataLabelingServiceClient->listEvaluationJobs($formattedParent); + $response = $dataLabelingServiceClient->listEvaluationJobs($request); /** @var EvaluationJob $element */ foreach ($response as $element) { diff --git a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/list_examples.php b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/list_examples.php index 3c363a768b7e..ebdd7c6417be 100644 --- a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/list_examples.php +++ b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/list_examples.php @@ -25,8 +25,9 @@ // [START datalabeling_v1beta1_generated_DataLabelingService_ListExamples_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; -use Google\Cloud\DataLabeling\V1beta1\DataLabelingServiceClient; +use Google\Cloud\DataLabeling\V1beta1\Client\DataLabelingServiceClient; use Google\Cloud\DataLabeling\V1beta1\Example; +use Google\Cloud\DataLabeling\V1beta1\ListExamplesRequest; /** * Lists examples in an annotated dataset. Pagination is supported. @@ -39,10 +40,14 @@ function list_examples_sample(string $formattedParent): void // Create a client. $dataLabelingServiceClient = new DataLabelingServiceClient(); + // Prepare the request message. + $request = (new ListExamplesRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $dataLabelingServiceClient->listExamples($formattedParent); + $response = $dataLabelingServiceClient->listExamples($request); /** @var Example $element */ foreach ($response as $element) { diff --git a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/list_instructions.php b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/list_instructions.php index 51a41a265c42..e2a60ee9bd13 100644 --- a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/list_instructions.php +++ b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/list_instructions.php @@ -25,8 +25,9 @@ // [START datalabeling_v1beta1_generated_DataLabelingService_ListInstructions_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; -use Google\Cloud\DataLabeling\V1beta1\DataLabelingServiceClient; +use Google\Cloud\DataLabeling\V1beta1\Client\DataLabelingServiceClient; use Google\Cloud\DataLabeling\V1beta1\Instruction; +use Google\Cloud\DataLabeling\V1beta1\ListInstructionsRequest; /** * Lists instructions for a project. Pagination is supported. @@ -40,10 +41,14 @@ function list_instructions_sample(string $formattedParent): void // Create a client. $dataLabelingServiceClient = new DataLabelingServiceClient(); + // Prepare the request message. + $request = (new ListInstructionsRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $dataLabelingServiceClient->listInstructions($formattedParent); + $response = $dataLabelingServiceClient->listInstructions($request); /** @var Instruction $element */ foreach ($response as $element) { diff --git a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/pause_evaluation_job.php b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/pause_evaluation_job.php index 28f3d5ac0234..37cfca70a324 100644 --- a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/pause_evaluation_job.php +++ b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/pause_evaluation_job.php @@ -24,7 +24,8 @@ // [START datalabeling_v1beta1_generated_DataLabelingService_PauseEvaluationJob_sync] use Google\ApiCore\ApiException; -use Google\Cloud\DataLabeling\V1beta1\DataLabelingServiceClient; +use Google\Cloud\DataLabeling\V1beta1\Client\DataLabelingServiceClient; +use Google\Cloud\DataLabeling\V1beta1\PauseEvaluationJobRequest; /** * Pauses an evaluation job. Pausing an evaluation job that is already in a @@ -40,9 +41,13 @@ function pause_evaluation_job_sample(string $formattedName): void // Create a client. $dataLabelingServiceClient = new DataLabelingServiceClient(); + // Prepare the request message. + $request = (new PauseEvaluationJobRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { - $dataLabelingServiceClient->pauseEvaluationJob($formattedName); + $dataLabelingServiceClient->pauseEvaluationJob($request); printf('Call completed successfully.' . PHP_EOL); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/resume_evaluation_job.php b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/resume_evaluation_job.php index 5cc27e1669f1..88708a65b642 100644 --- a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/resume_evaluation_job.php +++ b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/resume_evaluation_job.php @@ -24,7 +24,8 @@ // [START datalabeling_v1beta1_generated_DataLabelingService_ResumeEvaluationJob_sync] use Google\ApiCore\ApiException; -use Google\Cloud\DataLabeling\V1beta1\DataLabelingServiceClient; +use Google\Cloud\DataLabeling\V1beta1\Client\DataLabelingServiceClient; +use Google\Cloud\DataLabeling\V1beta1\ResumeEvaluationJobRequest; /** * Resumes a paused evaluation job. A deleted evaluation job can't be resumed. @@ -40,9 +41,13 @@ function resume_evaluation_job_sample(string $formattedName): void // Create a client. $dataLabelingServiceClient = new DataLabelingServiceClient(); + // Prepare the request message. + $request = (new ResumeEvaluationJobRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { - $dataLabelingServiceClient->resumeEvaluationJob($formattedName); + $dataLabelingServiceClient->resumeEvaluationJob($request); printf('Call completed successfully.' . PHP_EOL); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/search_evaluations.php b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/search_evaluations.php index 19cce4791d93..a2a549d5c7d8 100644 --- a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/search_evaluations.php +++ b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/search_evaluations.php @@ -25,8 +25,9 @@ // [START datalabeling_v1beta1_generated_DataLabelingService_SearchEvaluations_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; -use Google\Cloud\DataLabeling\V1beta1\DataLabelingServiceClient; +use Google\Cloud\DataLabeling\V1beta1\Client\DataLabelingServiceClient; use Google\Cloud\DataLabeling\V1beta1\Evaluation; +use Google\Cloud\DataLabeling\V1beta1\SearchEvaluationsRequest; /** * Searches [evaluations][google.cloud.datalabeling.v1beta1.Evaluation] within a project. @@ -40,10 +41,14 @@ function search_evaluations_sample(string $formattedParent): void // Create a client. $dataLabelingServiceClient = new DataLabelingServiceClient(); + // Prepare the request message. + $request = (new SearchEvaluationsRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $dataLabelingServiceClient->searchEvaluations($formattedParent); + $response = $dataLabelingServiceClient->searchEvaluations($request); /** @var Evaluation $element */ foreach ($response as $element) { diff --git a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/search_example_comparisons.php b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/search_example_comparisons.php index 360fd9b80bf0..b72c77f1283e 100644 --- a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/search_example_comparisons.php +++ b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/search_example_comparisons.php @@ -25,7 +25,8 @@ // [START datalabeling_v1beta1_generated_DataLabelingService_SearchExampleComparisons_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; -use Google\Cloud\DataLabeling\V1beta1\DataLabelingServiceClient; +use Google\Cloud\DataLabeling\V1beta1\Client\DataLabelingServiceClient; +use Google\Cloud\DataLabeling\V1beta1\SearchExampleComparisonsRequest; use Google\Cloud\DataLabeling\V1beta1\SearchExampleComparisonsResponse\ExampleComparison; /** @@ -44,10 +45,14 @@ function search_example_comparisons_sample(string $formattedParent): void // Create a client. $dataLabelingServiceClient = new DataLabelingServiceClient(); + // Prepare the request message. + $request = (new SearchExampleComparisonsRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $dataLabelingServiceClient->searchExampleComparisons($formattedParent); + $response = $dataLabelingServiceClient->searchExampleComparisons($request); /** @var ExampleComparison $element */ foreach ($response as $element) { diff --git a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/update_evaluation_job.php b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/update_evaluation_job.php index b8a360bbce19..ca30b25661f1 100644 --- a/DataLabeling/samples/V1beta1/DataLabelingServiceClient/update_evaluation_job.php +++ b/DataLabeling/samples/V1beta1/DataLabelingServiceClient/update_evaluation_job.php @@ -24,8 +24,9 @@ // [START datalabeling_v1beta1_generated_DataLabelingService_UpdateEvaluationJob_sync] use Google\ApiCore\ApiException; -use Google\Cloud\DataLabeling\V1beta1\DataLabelingServiceClient; +use Google\Cloud\DataLabeling\V1beta1\Client\DataLabelingServiceClient; use Google\Cloud\DataLabeling\V1beta1\EvaluationJob; +use Google\Cloud\DataLabeling\V1beta1\UpdateEvaluationJobRequest; /** * Updates an evaluation job. You can only update certain fields of the job's @@ -46,13 +47,15 @@ function update_evaluation_job_sample(): void // Create a client. $dataLabelingServiceClient = new DataLabelingServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $evaluationJob = new EvaluationJob(); + $request = (new UpdateEvaluationJobRequest()) + ->setEvaluationJob($evaluationJob); // Call the API and handle any network failures. try { /** @var EvaluationJob $response */ - $response = $dataLabelingServiceClient->updateEvaluationJob($evaluationJob); + $response = $dataLabelingServiceClient->updateEvaluationJob($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/DataLabeling/src/V1beta1/Client/BaseClient/DataLabelingServiceBaseClient.php b/DataLabeling/src/V1beta1/Client/BaseClient/DataLabelingServiceBaseClient.php new file mode 100644 index 000000000000..250d19ea22df --- /dev/null +++ b/DataLabeling/src/V1beta1/Client/BaseClient/DataLabelingServiceBaseClient.php @@ -0,0 +1,1389 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/data_labeling_service_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/data_labeling_service_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/data_labeling_service_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/data_labeling_service_rest_client_config.php', + ], + ], + ]; + } + + /** + * Return an OperationsClient object with the same endpoint as $this. + * + * @return OperationsClient + * + * @experimental + */ + public function getOperationsClient() + { + return $this->operationsClient; + } + + /** + * Resume an existing long running operation that was previously started by a long + * running API method. If $methodName is not provided, or does not match a long + * running API method, then the operation can still be resumed, but the + * OperationResponse object will not deserialize the final response. + * + * @param string $operationName The name of the long running operation + * @param string $methodName The name of the method used to start the operation + * + * @return OperationResponse + * + * @experimental + */ + public function resumeOperation($operationName, $methodName = null) + { + $options = isset($this->descriptors[$methodName]['longRunning']) ? $this->descriptors[$methodName]['longRunning'] : []; + $operation = new OperationResponse($operationName, $this->getOperationsClient(), $options); + $operation->reload(); + return $operation; + } + + /** + * Formats a string containing the fully-qualified path to represent a + * annotated_dataset resource. + * + * @param string $project + * @param string $dataset + * @param string $annotatedDataset + * + * @return string The formatted annotated_dataset resource. + * + * @experimental + */ + public static function annotatedDatasetName(string $project, string $dataset, string $annotatedDataset): string + { + return self::getPathTemplate('annotatedDataset')->render([ + 'project' => $project, + 'dataset' => $dataset, + 'annotated_dataset' => $annotatedDataset, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a + * annotation_spec_set resource. + * + * @param string $project + * @param string $annotationSpecSet + * + * @return string The formatted annotation_spec_set resource. + * + * @experimental + */ + public static function annotationSpecSetName(string $project, string $annotationSpecSet): string + { + return self::getPathTemplate('annotationSpecSet')->render([ + 'project' => $project, + 'annotation_spec_set' => $annotationSpecSet, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a data_item + * resource. + * + * @param string $project + * @param string $dataset + * @param string $dataItem + * + * @return string The formatted data_item resource. + * + * @experimental + */ + public static function dataItemName(string $project, string $dataset, string $dataItem): string + { + return self::getPathTemplate('dataItem')->render([ + 'project' => $project, + 'dataset' => $dataset, + 'data_item' => $dataItem, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a dataset + * resource. + * + * @param string $project + * @param string $dataset + * + * @return string The formatted dataset resource. + * + * @experimental + */ + public static function datasetName(string $project, string $dataset): string + { + return self::getPathTemplate('dataset')->render([ + 'project' => $project, + 'dataset' => $dataset, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a evaluation + * resource. + * + * @param string $project + * @param string $dataset + * @param string $evaluation + * + * @return string The formatted evaluation resource. + * + * @experimental + */ + public static function evaluationName(string $project, string $dataset, string $evaluation): string + { + return self::getPathTemplate('evaluation')->render([ + 'project' => $project, + 'dataset' => $dataset, + 'evaluation' => $evaluation, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a + * evaluation_job resource. + * + * @param string $project + * @param string $evaluationJob + * + * @return string The formatted evaluation_job resource. + * + * @experimental + */ + public static function evaluationJobName(string $project, string $evaluationJob): string + { + return self::getPathTemplate('evaluationJob')->render([ + 'project' => $project, + 'evaluation_job' => $evaluationJob, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a example + * resource. + * + * @param string $project + * @param string $dataset + * @param string $annotatedDataset + * @param string $example + * + * @return string The formatted example resource. + * + * @experimental + */ + public static function exampleName(string $project, string $dataset, string $annotatedDataset, string $example): string + { + return self::getPathTemplate('example')->render([ + 'project' => $project, + 'dataset' => $dataset, + 'annotated_dataset' => $annotatedDataset, + 'example' => $example, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a instruction + * resource. + * + * @param string $project + * @param string $instruction + * + * @return string The formatted instruction resource. + * + * @experimental + */ + public static function instructionName(string $project, string $instruction): string + { + return self::getPathTemplate('instruction')->render([ + 'project' => $project, + 'instruction' => $instruction, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a project + * resource. + * + * @param string $project + * + * @return string The formatted project resource. + * + * @experimental + */ + public static function projectName(string $project): string + { + return self::getPathTemplate('project')->render([ + 'project' => $project, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * Template: Pattern + * - annotatedDataset: projects/{project}/datasets/{dataset}/annotatedDatasets/{annotated_dataset} + * - annotationSpecSet: projects/{project}/annotationSpecSets/{annotation_spec_set} + * - dataItem: projects/{project}/datasets/{dataset}/dataItems/{data_item} + * - dataset: projects/{project}/datasets/{dataset} + * - evaluation: projects/{project}/datasets/{dataset}/evaluations/{evaluation} + * - evaluationJob: projects/{project}/evaluationJobs/{evaluation_job} + * - example: projects/{project}/datasets/{dataset}/annotatedDatasets/{annotated_dataset}/examples/{example} + * - instruction: projects/{project}/instructions/{instruction} + * - project: projects/{project} + * + * The optional $template argument can be supplied to specify a particular pattern, + * and must match one of the templates listed above. If no $template argument is + * provided, or if the $template argument does not match one of the templates + * listed, then parseName will check each of the supported templates, and return + * the first match. + * + * @param string $formattedName The formatted name string + * @param string $template Optional name of template to match + * + * @return array An associative array from name component IDs to component values. + * + * @throws ValidationException If $formattedName could not be matched. + * + * @experimental + */ + public static function parseName(string $formattedName, string $template = null): array + { + return self::parseFormattedName($formattedName, $template); + } + + /** + * Constructor. + * + * @param array $options { + * Optional. Options for configuring the service API wrapper. + * + * @type string $apiEndpoint + * The address of the API remote host. May optionally include the port, formatted + * as ":". Default 'datalabeling.googleapis.com:443'. + * @type string|array|FetchAuthTokenInterface|CredentialsWrapper $credentials + * The credentials to be used by the client to authorize API calls. This option + * accepts either a path to a credentials file, or a decoded credentials file as a + * PHP array. + * *Advanced usage*: In addition, this option can also accept a pre-constructed + * {@see \Google\Auth\FetchAuthTokenInterface} object or + * {@see \Google\ApiCore\CredentialsWrapper} object. Note that when one of these + * objects are provided, any settings in $credentialsConfig will be ignored. + * @type array $credentialsConfig + * Options used to configure credentials, including auth token caching, for the + * client. For a full list of supporting configuration options, see + * {@see \Google\ApiCore\CredentialsWrapper::build()} . + * @type bool $disableRetries + * Determines whether or not retries defined by the client configuration should be + * disabled. Defaults to `false`. + * @type string|array $clientConfig + * Client method configuration, including retry settings. This option can be either + * a path to a JSON file, or a PHP array containing the decoded JSON data. By + * default this settings points to the default client config file, which is + * provided in the resources folder. + * @type string|TransportInterface $transport + * The transport used for executing network requests. May be either the string + * `rest` or `grpc`. Defaults to `grpc` if gRPC support is detected on the system. + * *Advanced usage*: Additionally, it is possible to pass in an already + * instantiated {@see \Google\ApiCore\Transport\TransportInterface} object. Note + * that when this object is provided, any settings in $transportConfig, and any + * $apiEndpoint setting, will be ignored. + * @type array $transportConfig + * Configuration options that will be used to construct the transport. Options for + * each supported transport type should be passed in a key for that transport. For + * example: + * $transportConfig = [ + * 'grpc' => [...], + * 'rest' => [...], + * ]; + * See the {@see \Google\ApiCore\Transport\GrpcTransport::build()} and + * {@see \Google\ApiCore\Transport\RestTransport::build()} methods for the + * supported options. + * @type callable $clientCertSource + * A callable which returns the client cert as a string. This can be used to + * provide a certificate and private key to the transport layer for mTLS. + * } + * + * @throws ValidationException + * + * @experimental + */ + public function __construct(array $options = []) + { + $clientOptions = $this->buildClientOptions($options); + $this->setClientOptions($clientOptions); + $this->operationsClient = $this->createOperationsClient($clientOptions); + } + + /** Handles execution of the async variants for each documented method. */ + public function __call($method, $args) + { + if (substr($method, -5) !== 'Async') { + trigger_error('Call to undefined method ' . __CLASS__ . "::$method()", E_USER_ERROR); + } + + array_unshift($args, substr($method, 0, -5)); + return call_user_func_array([$this, 'startAsyncCall'], $args); + } + + /** + * Creates an annotation spec set by providing a set of labels. + * + * The async variant is {@see self::createAnnotationSpecSetAsync()} . + * + * @param CreateAnnotationSpecSetRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return AnnotationSpecSet + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function createAnnotationSpecSet(CreateAnnotationSpecSetRequest $request, array $callOptions = []): AnnotationSpecSet + { + return $this->startApiCall('CreateAnnotationSpecSet', $request, $callOptions)->wait(); + } + + /** + * Creates dataset. If success return a Dataset resource. + * + * The async variant is {@see self::createDatasetAsync()} . + * + * @param CreateDatasetRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Dataset + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function createDataset(CreateDatasetRequest $request, array $callOptions = []): Dataset + { + return $this->startApiCall('CreateDataset', $request, $callOptions)->wait(); + } + + /** + * Creates an evaluation job. + * + * The async variant is {@see self::createEvaluationJobAsync()} . + * + * @param CreateEvaluationJobRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return EvaluationJob + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function createEvaluationJob(CreateEvaluationJobRequest $request, array $callOptions = []): EvaluationJob + { + return $this->startApiCall('CreateEvaluationJob', $request, $callOptions)->wait(); + } + + /** + * Creates an instruction for how data should be labeled. + * + * The async variant is {@see self::createInstructionAsync()} . + * + * @param CreateInstructionRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function createInstruction(CreateInstructionRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('CreateInstruction', $request, $callOptions)->wait(); + } + + /** + * Deletes an annotated dataset by resource name. + * + * The async variant is {@see self::deleteAnnotatedDatasetAsync()} . + * + * @param DeleteAnnotatedDatasetRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function deleteAnnotatedDataset(DeleteAnnotatedDatasetRequest $request, array $callOptions = []): void + { + $this->startApiCall('DeleteAnnotatedDataset', $request, $callOptions)->wait(); + } + + /** + * Deletes an annotation spec set by resource name. + * + * The async variant is {@see self::deleteAnnotationSpecSetAsync()} . + * + * @param DeleteAnnotationSpecSetRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function deleteAnnotationSpecSet(DeleteAnnotationSpecSetRequest $request, array $callOptions = []): void + { + $this->startApiCall('DeleteAnnotationSpecSet', $request, $callOptions)->wait(); + } + + /** + * Deletes a dataset by resource name. + * + * The async variant is {@see self::deleteDatasetAsync()} . + * + * @param DeleteDatasetRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function deleteDataset(DeleteDatasetRequest $request, array $callOptions = []): void + { + $this->startApiCall('DeleteDataset', $request, $callOptions)->wait(); + } + + /** + * Stops and deletes an evaluation job. + * + * The async variant is {@see self::deleteEvaluationJobAsync()} . + * + * @param DeleteEvaluationJobRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function deleteEvaluationJob(DeleteEvaluationJobRequest $request, array $callOptions = []): void + { + $this->startApiCall('DeleteEvaluationJob', $request, $callOptions)->wait(); + } + + /** + * Deletes an instruction object by resource name. + * + * The async variant is {@see self::deleteInstructionAsync()} . + * + * @param DeleteInstructionRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function deleteInstruction(DeleteInstructionRequest $request, array $callOptions = []): void + { + $this->startApiCall('DeleteInstruction', $request, $callOptions)->wait(); + } + + /** + * Exports data and annotations from dataset. + * + * The async variant is {@see self::exportDataAsync()} . + * + * @param ExportDataRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function exportData(ExportDataRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('ExportData', $request, $callOptions)->wait(); + } + + /** + * Gets an annotated dataset by resource name. + * + * The async variant is {@see self::getAnnotatedDatasetAsync()} . + * + * @param GetAnnotatedDatasetRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return AnnotatedDataset + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function getAnnotatedDataset(GetAnnotatedDatasetRequest $request, array $callOptions = []): AnnotatedDataset + { + return $this->startApiCall('GetAnnotatedDataset', $request, $callOptions)->wait(); + } + + /** + * Gets an annotation spec set by resource name. + * + * The async variant is {@see self::getAnnotationSpecSetAsync()} . + * + * @param GetAnnotationSpecSetRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return AnnotationSpecSet + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function getAnnotationSpecSet(GetAnnotationSpecSetRequest $request, array $callOptions = []): AnnotationSpecSet + { + return $this->startApiCall('GetAnnotationSpecSet', $request, $callOptions)->wait(); + } + + /** + * Gets a data item in a dataset by resource name. This API can be + * called after data are imported into dataset. + * + * The async variant is {@see self::getDataItemAsync()} . + * + * @param GetDataItemRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return DataItem + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function getDataItem(GetDataItemRequest $request, array $callOptions = []): DataItem + { + return $this->startApiCall('GetDataItem', $request, $callOptions)->wait(); + } + + /** + * Gets dataset by resource name. + * + * The async variant is {@see self::getDatasetAsync()} . + * + * @param GetDatasetRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Dataset + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function getDataset(GetDatasetRequest $request, array $callOptions = []): Dataset + { + return $this->startApiCall('GetDataset', $request, $callOptions)->wait(); + } + + /** + * Gets an evaluation by resource name (to search, use + * [projects.evaluations.search][google.cloud.datalabeling.v1beta1.DataLabelingService.SearchEvaluations]). + * + * The async variant is {@see self::getEvaluationAsync()} . + * + * @param GetEvaluationRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Evaluation + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function getEvaluation(GetEvaluationRequest $request, array $callOptions = []): Evaluation + { + return $this->startApiCall('GetEvaluation', $request, $callOptions)->wait(); + } + + /** + * Gets an evaluation job by resource name. + * + * The async variant is {@see self::getEvaluationJobAsync()} . + * + * @param GetEvaluationJobRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return EvaluationJob + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function getEvaluationJob(GetEvaluationJobRequest $request, array $callOptions = []): EvaluationJob + { + return $this->startApiCall('GetEvaluationJob', $request, $callOptions)->wait(); + } + + /** + * Gets an example by resource name, including both data and annotation. + * + * The async variant is {@see self::getExampleAsync()} . + * + * @param GetExampleRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Example + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function getExample(GetExampleRequest $request, array $callOptions = []): Example + { + return $this->startApiCall('GetExample', $request, $callOptions)->wait(); + } + + /** + * Gets an instruction by resource name. + * + * The async variant is {@see self::getInstructionAsync()} . + * + * @param GetInstructionRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Instruction + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function getInstruction(GetInstructionRequest $request, array $callOptions = []): Instruction + { + return $this->startApiCall('GetInstruction', $request, $callOptions)->wait(); + } + + /** + * Imports data into dataset based on source locations defined in request. + * It can be called multiple times for the same dataset. Each dataset can + * only have one long running operation running on it. For example, no + * labeling task (also long running operation) can be started while + * importing is still ongoing. Vice versa. + * + * The async variant is {@see self::importDataAsync()} . + * + * @param ImportDataRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function importData(ImportDataRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('ImportData', $request, $callOptions)->wait(); + } + + /** + * Starts a labeling task for image. The type of image labeling task is + * configured by feature in the request. + * + * The async variant is {@see self::labelImageAsync()} . + * + * @param LabelImageRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function labelImage(LabelImageRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('LabelImage', $request, $callOptions)->wait(); + } + + /** + * Starts a labeling task for text. The type of text labeling task is + * configured by feature in the request. + * + * The async variant is {@see self::labelTextAsync()} . + * + * @param LabelTextRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function labelText(LabelTextRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('LabelText', $request, $callOptions)->wait(); + } + + /** + * Starts a labeling task for video. The type of video labeling task is + * configured by feature in the request. + * + * The async variant is {@see self::labelVideoAsync()} . + * + * @param LabelVideoRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function labelVideo(LabelVideoRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('LabelVideo', $request, $callOptions)->wait(); + } + + /** + * Lists annotated datasets for a dataset. Pagination is supported. + * + * The async variant is {@see self::listAnnotatedDatasetsAsync()} . + * + * @param ListAnnotatedDatasetsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function listAnnotatedDatasets(ListAnnotatedDatasetsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListAnnotatedDatasets', $request, $callOptions); + } + + /** + * Lists annotation spec sets for a project. Pagination is supported. + * + * The async variant is {@see self::listAnnotationSpecSetsAsync()} . + * + * @param ListAnnotationSpecSetsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function listAnnotationSpecSets(ListAnnotationSpecSetsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListAnnotationSpecSets', $request, $callOptions); + } + + /** + * Lists data items in a dataset. This API can be called after data + * are imported into dataset. Pagination is supported. + * + * The async variant is {@see self::listDataItemsAsync()} . + * + * @param ListDataItemsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function listDataItems(ListDataItemsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListDataItems', $request, $callOptions); + } + + /** + * Lists datasets under a project. Pagination is supported. + * + * The async variant is {@see self::listDatasetsAsync()} . + * + * @param ListDatasetsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function listDatasets(ListDatasetsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListDatasets', $request, $callOptions); + } + + /** + * Lists all evaluation jobs within a project with possible filters. + * Pagination is supported. + * + * The async variant is {@see self::listEvaluationJobsAsync()} . + * + * @param ListEvaluationJobsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function listEvaluationJobs(ListEvaluationJobsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListEvaluationJobs', $request, $callOptions); + } + + /** + * Lists examples in an annotated dataset. Pagination is supported. + * + * The async variant is {@see self::listExamplesAsync()} . + * + * @param ListExamplesRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function listExamples(ListExamplesRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListExamples', $request, $callOptions); + } + + /** + * Lists instructions for a project. Pagination is supported. + * + * The async variant is {@see self::listInstructionsAsync()} . + * + * @param ListInstructionsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function listInstructions(ListInstructionsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListInstructions', $request, $callOptions); + } + + /** + * Pauses an evaluation job. Pausing an evaluation job that is already in a + * `PAUSED` state is a no-op. + * + * The async variant is {@see self::pauseEvaluationJobAsync()} . + * + * @param PauseEvaluationJobRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function pauseEvaluationJob(PauseEvaluationJobRequest $request, array $callOptions = []): void + { + $this->startApiCall('PauseEvaluationJob', $request, $callOptions)->wait(); + } + + /** + * Resumes a paused evaluation job. A deleted evaluation job can't be resumed. + * Resuming a running or scheduled evaluation job is a no-op. + * + * The async variant is {@see self::resumeEvaluationJobAsync()} . + * + * @param ResumeEvaluationJobRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function resumeEvaluationJob(ResumeEvaluationJobRequest $request, array $callOptions = []): void + { + $this->startApiCall('ResumeEvaluationJob', $request, $callOptions)->wait(); + } + + /** + * Searches [evaluations][google.cloud.datalabeling.v1beta1.Evaluation] within a project. + * + * The async variant is {@see self::searchEvaluationsAsync()} . + * + * @param SearchEvaluationsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function searchEvaluations(SearchEvaluationsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('SearchEvaluations', $request, $callOptions); + } + + /** + * Searches example comparisons from an evaluation. The return format is a + * list of example comparisons that show ground truth and prediction(s) for + * a single input. Search by providing an evaluation ID. + * + * The async variant is {@see self::searchExampleComparisonsAsync()} . + * + * @param SearchExampleComparisonsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function searchExampleComparisons(SearchExampleComparisonsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('SearchExampleComparisons', $request, $callOptions); + } + + /** + * Updates an evaluation job. You can only update certain fields of the job's + * [EvaluationJobConfig][google.cloud.datalabeling.v1beta1.EvaluationJobConfig]: `humanAnnotationConfig.instruction`, + * `exampleCount`, and `exampleSamplePercentage`. + * + * If you want to change any other aspect of the evaluation job, you must + * delete the job and create a new one. + * + * The async variant is {@see self::updateEvaluationJobAsync()} . + * + * @param UpdateEvaluationJobRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return EvaluationJob + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function updateEvaluationJob(UpdateEvaluationJobRequest $request, array $callOptions = []): EvaluationJob + { + return $this->startApiCall('UpdateEvaluationJob', $request, $callOptions)->wait(); + } +} diff --git a/DataLabeling/src/V1beta1/Client/DataLabelingServiceClient.php b/DataLabeling/src/V1beta1/Client/DataLabelingServiceClient.php new file mode 100644 index 000000000000..bf1534d105d7 --- /dev/null +++ b/DataLabeling/src/V1beta1/Client/DataLabelingServiceClient.php @@ -0,0 +1,42 @@ +setParent($parent) + ->setAnnotationSpecSet($annotationSpecSet); + } + /** * Constructor. * diff --git a/DataLabeling/src/V1beta1/CreateDatasetRequest.php b/DataLabeling/src/V1beta1/CreateDatasetRequest.php index 24ba6a8815a7..c18ce558f4a4 100644 --- a/DataLabeling/src/V1beta1/CreateDatasetRequest.php +++ b/DataLabeling/src/V1beta1/CreateDatasetRequest.php @@ -29,6 +29,23 @@ class CreateDatasetRequest extends \Google\Protobuf\Internal\Message */ private $dataset = null; + /** + * @param string $parent Required. Dataset resource parent, format: + * projects/{project_id} + * Please see {@see DataLabelingServiceClient::projectName()} for help formatting this field. + * @param \Google\Cloud\DataLabeling\V1beta1\Dataset $dataset Required. The dataset to be created. + * + * @return \Google\Cloud\DataLabeling\V1beta1\CreateDatasetRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\DataLabeling\V1beta1\Dataset $dataset): self + { + return (new self()) + ->setParent($parent) + ->setDataset($dataset); + } + /** * Constructor. * diff --git a/DataLabeling/src/V1beta1/CreateEvaluationJobRequest.php b/DataLabeling/src/V1beta1/CreateEvaluationJobRequest.php index 972195368d03..9fa7efa1e631 100644 --- a/DataLabeling/src/V1beta1/CreateEvaluationJobRequest.php +++ b/DataLabeling/src/V1beta1/CreateEvaluationJobRequest.php @@ -29,6 +29,23 @@ class CreateEvaluationJobRequest extends \Google\Protobuf\Internal\Message */ private $job = null; + /** + * @param string $parent Required. Evaluation job resource parent. Format: + * "projects/{project_id}" + * Please see {@see DataLabelingServiceClient::projectName()} for help formatting this field. + * @param \Google\Cloud\DataLabeling\V1beta1\EvaluationJob $job Required. The evaluation job to create. + * + * @return \Google\Cloud\DataLabeling\V1beta1\CreateEvaluationJobRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\DataLabeling\V1beta1\EvaluationJob $job): self + { + return (new self()) + ->setParent($parent) + ->setJob($job); + } + /** * Constructor. * diff --git a/DataLabeling/src/V1beta1/CreateInstructionRequest.php b/DataLabeling/src/V1beta1/CreateInstructionRequest.php index 21d8d99707c9..919befc4c3da 100644 --- a/DataLabeling/src/V1beta1/CreateInstructionRequest.php +++ b/DataLabeling/src/V1beta1/CreateInstructionRequest.php @@ -29,6 +29,23 @@ class CreateInstructionRequest extends \Google\Protobuf\Internal\Message */ private $instruction = null; + /** + * @param string $parent Required. Instruction resource parent, format: + * projects/{project_id} + * Please see {@see DataLabelingServiceClient::projectName()} for help formatting this field. + * @param \Google\Cloud\DataLabeling\V1beta1\Instruction $instruction Required. Instruction of how to perform the labeling task. + * + * @return \Google\Cloud\DataLabeling\V1beta1\CreateInstructionRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\DataLabeling\V1beta1\Instruction $instruction): self + { + return (new self()) + ->setParent($parent) + ->setInstruction($instruction); + } + /** * Constructor. * diff --git a/DataLabeling/src/V1beta1/DeleteAnnotationSpecSetRequest.php b/DataLabeling/src/V1beta1/DeleteAnnotationSpecSetRequest.php index d58db6aa7512..b716be238531 100644 --- a/DataLabeling/src/V1beta1/DeleteAnnotationSpecSetRequest.php +++ b/DataLabeling/src/V1beta1/DeleteAnnotationSpecSetRequest.php @@ -23,6 +23,21 @@ class DeleteAnnotationSpecSetRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. AnnotationSpec resource name, format: + * `projects/{project_id}/annotationSpecSets/{annotation_spec_set_id}`. Please see + * {@see DataLabelingServiceClient::annotationSpecSetName()} for help formatting this field. + * + * @return \Google\Cloud\DataLabeling\V1beta1\DeleteAnnotationSpecSetRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/DataLabeling/src/V1beta1/DeleteDatasetRequest.php b/DataLabeling/src/V1beta1/DeleteDatasetRequest.php index ac59793f9e8f..6ecfa33b05d9 100644 --- a/DataLabeling/src/V1beta1/DeleteDatasetRequest.php +++ b/DataLabeling/src/V1beta1/DeleteDatasetRequest.php @@ -23,6 +23,21 @@ class DeleteDatasetRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. Dataset resource name, format: + * projects/{project_id}/datasets/{dataset_id} + * Please see {@see DataLabelingServiceClient::datasetName()} for help formatting this field. + * + * @return \Google\Cloud\DataLabeling\V1beta1\DeleteDatasetRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/DataLabeling/src/V1beta1/DeleteEvaluationJobRequest.php b/DataLabeling/src/V1beta1/DeleteEvaluationJobRequest.php index 0037c21ad02a..36717ee41a8c 100644 --- a/DataLabeling/src/V1beta1/DeleteEvaluationJobRequest.php +++ b/DataLabeling/src/V1beta1/DeleteEvaluationJobRequest.php @@ -23,6 +23,22 @@ class DeleteEvaluationJobRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. Name of the evaluation job that is going to be deleted. Format: + * + * "projects/{project_id}/evaluationJobs/{evaluation_job_id}" + * Please see {@see DataLabelingServiceClient::evaluationJobName()} for help formatting this field. + * + * @return \Google\Cloud\DataLabeling\V1beta1\DeleteEvaluationJobRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/DataLabeling/src/V1beta1/DeleteInstructionRequest.php b/DataLabeling/src/V1beta1/DeleteInstructionRequest.php index 4bf57189fb34..a6ff7a5b98cd 100644 --- a/DataLabeling/src/V1beta1/DeleteInstructionRequest.php +++ b/DataLabeling/src/V1beta1/DeleteInstructionRequest.php @@ -23,6 +23,21 @@ class DeleteInstructionRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. Instruction resource name, format: + * projects/{project_id}/instructions/{instruction_id} + * Please see {@see DataLabelingServiceClient::instructionName()} for help formatting this field. + * + * @return \Google\Cloud\DataLabeling\V1beta1\DeleteInstructionRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/DataLabeling/src/V1beta1/ExportDataRequest.php b/DataLabeling/src/V1beta1/ExportDataRequest.php index 71fdb7789502..190912b7f317 100644 --- a/DataLabeling/src/V1beta1/ExportDataRequest.php +++ b/DataLabeling/src/V1beta1/ExportDataRequest.php @@ -52,6 +52,32 @@ class ExportDataRequest extends \Google\Protobuf\Internal\Message */ private $user_email_address = ''; + /** + * @param string $name Required. Dataset resource name, format: + * projects/{project_id}/datasets/{dataset_id} + * Please see {@see DataLabelingServiceClient::datasetName()} for help formatting this field. + * @param string $annotatedDataset Required. Annotated dataset resource name. DataItem in + * Dataset and their annotations in specified annotated dataset will be + * exported. It's in format of + * projects/{project_id}/datasets/{dataset_id}/annotatedDatasets/ + * {annotated_dataset_id} + * Please see {@see DataLabelingServiceClient::annotatedDatasetName()} for help formatting this field. + * @param string $filter Optional. Filter is not supported at this moment. + * @param \Google\Cloud\DataLabeling\V1beta1\OutputConfig $outputConfig Required. Specify the output destination. + * + * @return \Google\Cloud\DataLabeling\V1beta1\ExportDataRequest + * + * @experimental + */ + public static function build(string $name, string $annotatedDataset, string $filter, \Google\Cloud\DataLabeling\V1beta1\OutputConfig $outputConfig): self + { + return (new self()) + ->setName($name) + ->setAnnotatedDataset($annotatedDataset) + ->setFilter($filter) + ->setOutputConfig($outputConfig); + } + /** * Constructor. * diff --git a/DataLabeling/src/V1beta1/GetAnnotatedDatasetRequest.php b/DataLabeling/src/V1beta1/GetAnnotatedDatasetRequest.php index c2ddad38e9a9..61db39c8958a 100644 --- a/DataLabeling/src/V1beta1/GetAnnotatedDatasetRequest.php +++ b/DataLabeling/src/V1beta1/GetAnnotatedDatasetRequest.php @@ -24,6 +24,22 @@ class GetAnnotatedDatasetRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. Name of the annotated dataset to get, format: + * projects/{project_id}/datasets/{dataset_id}/annotatedDatasets/ + * {annotated_dataset_id} + * Please see {@see DataLabelingServiceClient::annotatedDatasetName()} for help formatting this field. + * + * @return \Google\Cloud\DataLabeling\V1beta1\GetAnnotatedDatasetRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/DataLabeling/src/V1beta1/GetAnnotationSpecSetRequest.php b/DataLabeling/src/V1beta1/GetAnnotationSpecSetRequest.php index ffb3a4cea2c6..ec888645d6f2 100644 --- a/DataLabeling/src/V1beta1/GetAnnotationSpecSetRequest.php +++ b/DataLabeling/src/V1beta1/GetAnnotationSpecSetRequest.php @@ -23,6 +23,21 @@ class GetAnnotationSpecSetRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. AnnotationSpecSet resource name, format: + * projects/{project_id}/annotationSpecSets/{annotation_spec_set_id} + * Please see {@see DataLabelingServiceClient::annotationSpecSetName()} for help formatting this field. + * + * @return \Google\Cloud\DataLabeling\V1beta1\GetAnnotationSpecSetRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/DataLabeling/src/V1beta1/GetDataItemRequest.php b/DataLabeling/src/V1beta1/GetDataItemRequest.php index 709d6c01b046..64cf5bed8eee 100644 --- a/DataLabeling/src/V1beta1/GetDataItemRequest.php +++ b/DataLabeling/src/V1beta1/GetDataItemRequest.php @@ -23,6 +23,21 @@ class GetDataItemRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The name of the data item to get, format: + * projects/{project_id}/datasets/{dataset_id}/dataItems/{data_item_id} + * Please see {@see DataLabelingServiceClient::dataItemName()} for help formatting this field. + * + * @return \Google\Cloud\DataLabeling\V1beta1\GetDataItemRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/DataLabeling/src/V1beta1/GetDatasetRequest.php b/DataLabeling/src/V1beta1/GetDatasetRequest.php index eaf6eb71da93..ce15722e551d 100644 --- a/DataLabeling/src/V1beta1/GetDatasetRequest.php +++ b/DataLabeling/src/V1beta1/GetDatasetRequest.php @@ -23,6 +23,21 @@ class GetDatasetRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. Dataset resource name, format: + * projects/{project_id}/datasets/{dataset_id} + * Please see {@see DataLabelingServiceClient::datasetName()} for help formatting this field. + * + * @return \Google\Cloud\DataLabeling\V1beta1\GetDatasetRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/DataLabeling/src/V1beta1/GetEvaluationJobRequest.php b/DataLabeling/src/V1beta1/GetEvaluationJobRequest.php index 0809cad4c414..c8679c91079e 100644 --- a/DataLabeling/src/V1beta1/GetEvaluationJobRequest.php +++ b/DataLabeling/src/V1beta1/GetEvaluationJobRequest.php @@ -23,6 +23,22 @@ class GetEvaluationJobRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. Name of the evaluation job. Format: + * + * "projects/{project_id}/evaluationJobs/{evaluation_job_id}" + * Please see {@see DataLabelingServiceClient::evaluationJobName()} for help formatting this field. + * + * @return \Google\Cloud\DataLabeling\V1beta1\GetEvaluationJobRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/DataLabeling/src/V1beta1/GetEvaluationRequest.php b/DataLabeling/src/V1beta1/GetEvaluationRequest.php index 10ea11a07248..fe3dae048735 100644 --- a/DataLabeling/src/V1beta1/GetEvaluationRequest.php +++ b/DataLabeling/src/V1beta1/GetEvaluationRequest.php @@ -23,6 +23,22 @@ class GetEvaluationRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. Name of the evaluation. Format: + * + * "projects/{project_id}/datasets/{dataset_id}/evaluations/{evaluation_id}' + * Please see {@see DataLabelingServiceClient::evaluationName()} for help formatting this field. + * + * @return \Google\Cloud\DataLabeling\V1beta1\GetEvaluationRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/DataLabeling/src/V1beta1/GetExampleRequest.php b/DataLabeling/src/V1beta1/GetExampleRequest.php index 2ecde5032735..a501296de8e5 100644 --- a/DataLabeling/src/V1beta1/GetExampleRequest.php +++ b/DataLabeling/src/V1beta1/GetExampleRequest.php @@ -32,6 +32,26 @@ class GetExampleRequest extends \Google\Protobuf\Internal\Message */ private $filter = ''; + /** + * @param string $name Required. Name of example, format: + * projects/{project_id}/datasets/{dataset_id}/annotatedDatasets/ + * {annotated_dataset_id}/examples/{example_id} + * Please see {@see DataLabelingServiceClient::exampleName()} for help formatting this field. + * @param string $filter Optional. An expression for filtering Examples. Filter by + * annotation_spec.display_name is supported. Format + * "annotation_spec.display_name = {display_name}" + * + * @return \Google\Cloud\DataLabeling\V1beta1\GetExampleRequest + * + * @experimental + */ + public static function build(string $name, string $filter): self + { + return (new self()) + ->setName($name) + ->setFilter($filter); + } + /** * Constructor. * diff --git a/DataLabeling/src/V1beta1/GetInstructionRequest.php b/DataLabeling/src/V1beta1/GetInstructionRequest.php index c7662aba6417..8c69ffdefbb8 100644 --- a/DataLabeling/src/V1beta1/GetInstructionRequest.php +++ b/DataLabeling/src/V1beta1/GetInstructionRequest.php @@ -23,6 +23,21 @@ class GetInstructionRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. Instruction resource name, format: + * projects/{project_id}/instructions/{instruction_id} + * Please see {@see DataLabelingServiceClient::instructionName()} for help formatting this field. + * + * @return \Google\Cloud\DataLabeling\V1beta1\GetInstructionRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/DataLabeling/src/V1beta1/ImportDataRequest.php b/DataLabeling/src/V1beta1/ImportDataRequest.php index bcdbf2fb712e..e111bf578aec 100644 --- a/DataLabeling/src/V1beta1/ImportDataRequest.php +++ b/DataLabeling/src/V1beta1/ImportDataRequest.php @@ -36,6 +36,23 @@ class ImportDataRequest extends \Google\Protobuf\Internal\Message */ private $user_email_address = ''; + /** + * @param string $name Required. Dataset resource name, format: + * projects/{project_id}/datasets/{dataset_id} + * Please see {@see DataLabelingServiceClient::datasetName()} for help formatting this field. + * @param \Google\Cloud\DataLabeling\V1beta1\InputConfig $inputConfig Required. Specify the input source of the data. + * + * @return \Google\Cloud\DataLabeling\V1beta1\ImportDataRequest + * + * @experimental + */ + public static function build(string $name, \Google\Cloud\DataLabeling\V1beta1\InputConfig $inputConfig): self + { + return (new self()) + ->setName($name) + ->setInputConfig($inputConfig); + } + /** * Constructor. * diff --git a/DataLabeling/src/V1beta1/LabelImageRequest.php b/DataLabeling/src/V1beta1/LabelImageRequest.php index dac4b534e3cb..e71b0dad1785 100644 --- a/DataLabeling/src/V1beta1/LabelImageRequest.php +++ b/DataLabeling/src/V1beta1/LabelImageRequest.php @@ -36,6 +36,26 @@ class LabelImageRequest extends \Google\Protobuf\Internal\Message private $feature = 0; protected $request_config; + /** + * @param string $parent Required. Name of the dataset to request labeling task, format: + * projects/{project_id}/datasets/{dataset_id} + * Please see {@see DataLabelingServiceClient::datasetName()} for help formatting this field. + * @param \Google\Cloud\DataLabeling\V1beta1\HumanAnnotationConfig $basicConfig Required. Basic human annotation config. + * @param int $feature Required. The type of image labeling task. + * For allowed values, use constants defined on {@see \Google\Cloud\DataLabeling\V1beta1\LabelImageRequest\Feature} + * + * @return \Google\Cloud\DataLabeling\V1beta1\LabelImageRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\DataLabeling\V1beta1\HumanAnnotationConfig $basicConfig, int $feature): self + { + return (new self()) + ->setParent($parent) + ->setBasicConfig($basicConfig) + ->setFeature($feature); + } + /** * Constructor. * diff --git a/DataLabeling/src/V1beta1/LabelTextRequest.php b/DataLabeling/src/V1beta1/LabelTextRequest.php index b3d1a610463d..92f90b20b48b 100644 --- a/DataLabeling/src/V1beta1/LabelTextRequest.php +++ b/DataLabeling/src/V1beta1/LabelTextRequest.php @@ -36,6 +36,26 @@ class LabelTextRequest extends \Google\Protobuf\Internal\Message private $feature = 0; protected $request_config; + /** + * @param string $parent Required. Name of the data set to request labeling task, format: + * projects/{project_id}/datasets/{dataset_id} + * Please see {@see DataLabelingServiceClient::datasetName()} for help formatting this field. + * @param \Google\Cloud\DataLabeling\V1beta1\HumanAnnotationConfig $basicConfig Required. Basic human annotation config. + * @param int $feature Required. The type of text labeling task. + * For allowed values, use constants defined on {@see \Google\Cloud\DataLabeling\V1beta1\LabelTextRequest\Feature} + * + * @return \Google\Cloud\DataLabeling\V1beta1\LabelTextRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\DataLabeling\V1beta1\HumanAnnotationConfig $basicConfig, int $feature): self + { + return (new self()) + ->setParent($parent) + ->setBasicConfig($basicConfig) + ->setFeature($feature); + } + /** * Constructor. * diff --git a/DataLabeling/src/V1beta1/LabelVideoRequest.php b/DataLabeling/src/V1beta1/LabelVideoRequest.php index 35c13970dd34..79aca15869e1 100644 --- a/DataLabeling/src/V1beta1/LabelVideoRequest.php +++ b/DataLabeling/src/V1beta1/LabelVideoRequest.php @@ -36,6 +36,26 @@ class LabelVideoRequest extends \Google\Protobuf\Internal\Message private $feature = 0; protected $request_config; + /** + * @param string $parent Required. Name of the dataset to request labeling task, format: + * projects/{project_id}/datasets/{dataset_id} + * Please see {@see DataLabelingServiceClient::datasetName()} for help formatting this field. + * @param \Google\Cloud\DataLabeling\V1beta1\HumanAnnotationConfig $basicConfig Required. Basic human annotation config. + * @param int $feature Required. The type of video labeling task. + * For allowed values, use constants defined on {@see \Google\Cloud\DataLabeling\V1beta1\LabelVideoRequest\Feature} + * + * @return \Google\Cloud\DataLabeling\V1beta1\LabelVideoRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\DataLabeling\V1beta1\HumanAnnotationConfig $basicConfig, int $feature): self + { + return (new self()) + ->setParent($parent) + ->setBasicConfig($basicConfig) + ->setFeature($feature); + } + /** * Constructor. * diff --git a/DataLabeling/src/V1beta1/ListAnnotatedDatasetsRequest.php b/DataLabeling/src/V1beta1/ListAnnotatedDatasetsRequest.php index 45fe0014377a..a1c13fcd1fd5 100644 --- a/DataLabeling/src/V1beta1/ListAnnotatedDatasetsRequest.php +++ b/DataLabeling/src/V1beta1/ListAnnotatedDatasetsRequest.php @@ -46,6 +46,23 @@ class ListAnnotatedDatasetsRequest extends \Google\Protobuf\Internal\Message */ private $page_token = ''; + /** + * @param string $parent Required. Name of the dataset to list annotated datasets, format: + * projects/{project_id}/datasets/{dataset_id} + * Please see {@see DataLabelingServiceClient::datasetName()} for help formatting this field. + * @param string $filter Optional. Filter is not supported at this moment. + * + * @return \Google\Cloud\DataLabeling\V1beta1\ListAnnotatedDatasetsRequest + * + * @experimental + */ + public static function build(string $parent, string $filter): self + { + return (new self()) + ->setParent($parent) + ->setFilter($filter); + } + /** * Constructor. * diff --git a/DataLabeling/src/V1beta1/ListAnnotationSpecSetsRequest.php b/DataLabeling/src/V1beta1/ListAnnotationSpecSetsRequest.php index b547357e6bdc..b4f725d4597c 100644 --- a/DataLabeling/src/V1beta1/ListAnnotationSpecSetsRequest.php +++ b/DataLabeling/src/V1beta1/ListAnnotationSpecSetsRequest.php @@ -46,6 +46,23 @@ class ListAnnotationSpecSetsRequest extends \Google\Protobuf\Internal\Message */ private $page_token = ''; + /** + * @param string $parent Required. Parent of AnnotationSpecSet resource, format: + * projects/{project_id} + * Please see {@see DataLabelingServiceClient::projectName()} for help formatting this field. + * @param string $filter Optional. Filter is not supported at this moment. + * + * @return \Google\Cloud\DataLabeling\V1beta1\ListAnnotationSpecSetsRequest + * + * @experimental + */ + public static function build(string $parent, string $filter): self + { + return (new self()) + ->setParent($parent) + ->setFilter($filter); + } + /** * Constructor. * diff --git a/DataLabeling/src/V1beta1/ListDataItemsRequest.php b/DataLabeling/src/V1beta1/ListDataItemsRequest.php index 8d199b49dfd5..f6391306e38b 100644 --- a/DataLabeling/src/V1beta1/ListDataItemsRequest.php +++ b/DataLabeling/src/V1beta1/ListDataItemsRequest.php @@ -46,6 +46,23 @@ class ListDataItemsRequest extends \Google\Protobuf\Internal\Message */ private $page_token = ''; + /** + * @param string $parent Required. Name of the dataset to list data items, format: + * projects/{project_id}/datasets/{dataset_id} + * Please see {@see DataLabelingServiceClient::datasetName()} for help formatting this field. + * @param string $filter Optional. Filter is not supported at this moment. + * + * @return \Google\Cloud\DataLabeling\V1beta1\ListDataItemsRequest + * + * @experimental + */ + public static function build(string $parent, string $filter): self + { + return (new self()) + ->setParent($parent) + ->setFilter($filter); + } + /** * Constructor. * diff --git a/DataLabeling/src/V1beta1/ListDatasetsRequest.php b/DataLabeling/src/V1beta1/ListDatasetsRequest.php index 1640fd40ca8d..e24e98eba5a2 100644 --- a/DataLabeling/src/V1beta1/ListDatasetsRequest.php +++ b/DataLabeling/src/V1beta1/ListDatasetsRequest.php @@ -46,6 +46,23 @@ class ListDatasetsRequest extends \Google\Protobuf\Internal\Message */ private $page_token = ''; + /** + * @param string $parent Required. Dataset resource parent, format: + * projects/{project_id} + * Please see {@see DataLabelingServiceClient::projectName()} for help formatting this field. + * @param string $filter Optional. Filter on dataset is not supported at this moment. + * + * @return \Google\Cloud\DataLabeling\V1beta1\ListDatasetsRequest + * + * @experimental + */ + public static function build(string $parent, string $filter): self + { + return (new self()) + ->setParent($parent) + ->setFilter($filter); + } + /** * Constructor. * diff --git a/DataLabeling/src/V1beta1/ListEvaluationJobsRequest.php b/DataLabeling/src/V1beta1/ListEvaluationJobsRequest.php index ffcffc576381..7d9f4727cc78 100644 --- a/DataLabeling/src/V1beta1/ListEvaluationJobsRequest.php +++ b/DataLabeling/src/V1beta1/ListEvaluationJobsRequest.php @@ -53,6 +53,30 @@ class ListEvaluationJobsRequest extends \Google\Protobuf\Internal\Message */ private $page_token = ''; + /** + * @param string $parent Required. Evaluation job resource parent. Format: + * "projects/{project_id}" + * Please see {@see DataLabelingServiceClient::projectName()} for help formatting this field. + * @param string $filter Optional. You can filter the jobs to list by model_id (also known as + * model_name, as described in + * [EvaluationJob.modelVersion][google.cloud.datalabeling.v1beta1.EvaluationJob.model_version]) or by + * evaluation job state (as described in [EvaluationJob.state][google.cloud.datalabeling.v1beta1.EvaluationJob.state]). To filter + * by both criteria, use the `AND` operator or the `OR` operator. For example, + * you can use the following string for your filter: + * "evaluation_job.model_id = {model_name} AND + * evaluation_job.state = {evaluation_job_state}" + * + * @return \Google\Cloud\DataLabeling\V1beta1\ListEvaluationJobsRequest + * + * @experimental + */ + public static function build(string $parent, string $filter): self + { + return (new self()) + ->setParent($parent) + ->setFilter($filter); + } + /** * Constructor. * diff --git a/DataLabeling/src/V1beta1/ListExamplesRequest.php b/DataLabeling/src/V1beta1/ListExamplesRequest.php index 05128cebde83..72dde00bf404 100644 --- a/DataLabeling/src/V1beta1/ListExamplesRequest.php +++ b/DataLabeling/src/V1beta1/ListExamplesRequest.php @@ -48,6 +48,25 @@ class ListExamplesRequest extends \Google\Protobuf\Internal\Message */ private $page_token = ''; + /** + * @param string $parent Required. Example resource parent. Please see + * {@see DataLabelingServiceClient::annotatedDatasetName()} for help formatting this field. + * @param string $filter Optional. An expression for filtering Examples. For annotated datasets that + * have annotation spec set, filter by + * annotation_spec.display_name is supported. Format + * "annotation_spec.display_name = {display_name}" + * + * @return \Google\Cloud\DataLabeling\V1beta1\ListExamplesRequest + * + * @experimental + */ + public static function build(string $parent, string $filter): self + { + return (new self()) + ->setParent($parent) + ->setFilter($filter); + } + /** * Constructor. * diff --git a/DataLabeling/src/V1beta1/ListInstructionsRequest.php b/DataLabeling/src/V1beta1/ListInstructionsRequest.php index d219fde87f7f..3e8cdaf25252 100644 --- a/DataLabeling/src/V1beta1/ListInstructionsRequest.php +++ b/DataLabeling/src/V1beta1/ListInstructionsRequest.php @@ -46,6 +46,23 @@ class ListInstructionsRequest extends \Google\Protobuf\Internal\Message */ private $page_token = ''; + /** + * @param string $parent Required. Instruction resource parent, format: + * projects/{project_id} + * Please see {@see DataLabelingServiceClient::projectName()} for help formatting this field. + * @param string $filter Optional. Filter is not supported at this moment. + * + * @return \Google\Cloud\DataLabeling\V1beta1\ListInstructionsRequest + * + * @experimental + */ + public static function build(string $parent, string $filter): self + { + return (new self()) + ->setParent($parent) + ->setFilter($filter); + } + /** * Constructor. * diff --git a/DataLabeling/src/V1beta1/PauseEvaluationJobRequest.php b/DataLabeling/src/V1beta1/PauseEvaluationJobRequest.php index 0c871857189c..e4b220b443d0 100644 --- a/DataLabeling/src/V1beta1/PauseEvaluationJobRequest.php +++ b/DataLabeling/src/V1beta1/PauseEvaluationJobRequest.php @@ -23,6 +23,22 @@ class PauseEvaluationJobRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. Name of the evaluation job that is going to be paused. Format: + * + * "projects/{project_id}/evaluationJobs/{evaluation_job_id}" + * Please see {@see DataLabelingServiceClient::evaluationJobName()} for help formatting this field. + * + * @return \Google\Cloud\DataLabeling\V1beta1\PauseEvaluationJobRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/DataLabeling/src/V1beta1/ResumeEvaluationJobRequest.php b/DataLabeling/src/V1beta1/ResumeEvaluationJobRequest.php index 9ff1a685ff93..36e909eeee23 100644 --- a/DataLabeling/src/V1beta1/ResumeEvaluationJobRequest.php +++ b/DataLabeling/src/V1beta1/ResumeEvaluationJobRequest.php @@ -23,6 +23,22 @@ class ResumeEvaluationJobRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. Name of the evaluation job that is going to be resumed. Format: + * + * "projects/{project_id}/evaluationJobs/{evaluation_job_id}" + * Please see {@see DataLabelingServiceClient::evaluationJobName()} for help formatting this field. + * + * @return \Google\Cloud\DataLabeling\V1beta1\ResumeEvaluationJobRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/DataLabeling/src/V1beta1/SearchEvaluationsRequest.php b/DataLabeling/src/V1beta1/SearchEvaluationsRequest.php index 604e9aff1d1f..e53f3d107197 100644 --- a/DataLabeling/src/V1beta1/SearchEvaluationsRequest.php +++ b/DataLabeling/src/V1beta1/SearchEvaluationsRequest.php @@ -74,6 +74,53 @@ class SearchEvaluationsRequest extends \Google\Protobuf\Internal\Message */ private $page_token = ''; + /** + * @param string $parent Required. Evaluation search parent (project ID). Format: + * "projects/{project_id}" + * Please see {@see DataLabelingServiceClient::evaluationName()} for help formatting this field. + * @param string $filter Optional. To search evaluations, you can filter by the following: + * + * * evaluation_job.evaluation_job_id (the last part of + * [EvaluationJob.name][google.cloud.datalabeling.v1beta1.EvaluationJob.name]) + * * evaluation_job.model_id (the {model_name} portion + * of [EvaluationJob.modelVersion][google.cloud.datalabeling.v1beta1.EvaluationJob.model_version]) + * * evaluation_job.evaluation_job_run_time_start (Minimum + * threshold for the + * [evaluationJobRunTime][google.cloud.datalabeling.v1beta1.Evaluation.evaluation_job_run_time] that created + * the evaluation) + * * evaluation_job.evaluation_job_run_time_end (Maximum + * threshold for the + * [evaluationJobRunTime][google.cloud.datalabeling.v1beta1.Evaluation.evaluation_job_run_time] that created + * the evaluation) + * * evaluation_job.job_state ([EvaluationJob.state][google.cloud.datalabeling.v1beta1.EvaluationJob.state]) + * * annotation_spec.display_name (the Evaluation contains a + * metric for the annotation spec with this + * [displayName][google.cloud.datalabeling.v1beta1.AnnotationSpec.display_name]) + * + * To filter by multiple critiera, use the `AND` operator or the `OR` + * operator. The following examples shows a string that filters by several + * critiera: + * + * "evaluation_job.evaluation_job_id = + * {evaluation_job_id} AND evaluation_job.model_id = + * {model_name} AND + * evaluation_job.evaluation_job_run_time_start = + * {timestamp_1} AND + * evaluation_job.evaluation_job_run_time_end = + * {timestamp_2} AND annotation_spec.display_name = + * {display_name}" + * + * @return \Google\Cloud\DataLabeling\V1beta1\SearchEvaluationsRequest + * + * @experimental + */ + public static function build(string $parent, string $filter): self + { + return (new self()) + ->setParent($parent) + ->setFilter($filter); + } + /** * Constructor. * diff --git a/DataLabeling/src/V1beta1/SearchExampleComparisonsRequest.php b/DataLabeling/src/V1beta1/SearchExampleComparisonsRequest.php index 31d182760ee1..50d139021b13 100644 --- a/DataLabeling/src/V1beta1/SearchExampleComparisonsRequest.php +++ b/DataLabeling/src/V1beta1/SearchExampleComparisonsRequest.php @@ -42,6 +42,23 @@ class SearchExampleComparisonsRequest extends \Google\Protobuf\Internal\Message */ private $page_token = ''; + /** + * @param string $parent Required. Name of the [Evaluation][google.cloud.datalabeling.v1beta1.Evaluation] resource to search for example + * comparisons from. Format: + * + * "projects/{project_id}/datasets/{dataset_id}/evaluations/{evaluation_id}" + * Please see {@see DataLabelingServiceClient::evaluationName()} for help formatting this field. + * + * @return \Google\Cloud\DataLabeling\V1beta1\SearchExampleComparisonsRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/DataLabeling/src/V1beta1/UpdateEvaluationJobRequest.php b/DataLabeling/src/V1beta1/UpdateEvaluationJobRequest.php index 13feff2cd161..dcefb85f98b0 100644 --- a/DataLabeling/src/V1beta1/UpdateEvaluationJobRequest.php +++ b/DataLabeling/src/V1beta1/UpdateEvaluationJobRequest.php @@ -34,6 +34,29 @@ class UpdateEvaluationJobRequest extends \Google\Protobuf\Internal\Message */ private $update_mask = null; + /** + * @param \Google\Cloud\DataLabeling\V1beta1\EvaluationJob $evaluationJob Required. Evaluation job that is going to be updated. + * @param \Google\Protobuf\FieldMask $updateMask Optional. Mask for which fields to update. You can only provide the + * following fields: + * + * * `evaluationJobConfig.humanAnnotationConfig.instruction` + * * `evaluationJobConfig.exampleCount` + * * `evaluationJobConfig.exampleSamplePercentage` + * + * You can provide more than one of these fields by separating them with + * commas. + * + * @return \Google\Cloud\DataLabeling\V1beta1\UpdateEvaluationJobRequest + * + * @experimental + */ + public static function build(\Google\Cloud\DataLabeling\V1beta1\EvaluationJob $evaluationJob, \Google\Protobuf\FieldMask $updateMask): self + { + return (new self()) + ->setEvaluationJob($evaluationJob) + ->setUpdateMask($updateMask); + } + /** * Constructor. * diff --git a/DataLabeling/src/V1beta1/resources/data_labeling_service_descriptor_config.php b/DataLabeling/src/V1beta1/resources/data_labeling_service_descriptor_config.php index 33241ecd081c..56369463b2fc 100644 --- a/DataLabeling/src/V1beta1/resources/data_labeling_service_descriptor_config.php +++ b/DataLabeling/src/V1beta1/resources/data_labeling_service_descriptor_config.php @@ -12,6 +12,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ExportData' => [ 'longRunning' => [ @@ -22,6 +31,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'ImportData' => [ 'longRunning' => [ @@ -32,6 +50,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'LabelImage' => [ 'longRunning' => [ @@ -42,6 +69,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'LabelText' => [ 'longRunning' => [ @@ -52,6 +88,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'LabelVideo' => [ 'longRunning' => [ @@ -62,6 +107,207 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'CreateAnnotationSpecSet' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\DataLabeling\V1beta1\AnnotationSpecSet', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'CreateDataset' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\DataLabeling\V1beta1\Dataset', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'CreateEvaluationJob' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\DataLabeling\V1beta1\EvaluationJob', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'DeleteAnnotatedDataset' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Protobuf\GPBEmpty', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'DeleteAnnotationSpecSet' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Protobuf\GPBEmpty', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'DeleteDataset' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Protobuf\GPBEmpty', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'DeleteEvaluationJob' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Protobuf\GPBEmpty', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'DeleteInstruction' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Protobuf\GPBEmpty', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetAnnotatedDataset' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\DataLabeling\V1beta1\AnnotatedDataset', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetAnnotationSpecSet' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\DataLabeling\V1beta1\AnnotationSpecSet', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetDataItem' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\DataLabeling\V1beta1\DataItem', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetDataset' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\DataLabeling\V1beta1\Dataset', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetEvaluation' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\DataLabeling\V1beta1\Evaluation', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetEvaluationJob' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\DataLabeling\V1beta1\EvaluationJob', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetExample' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\DataLabeling\V1beta1\Example', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetInstruction' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\DataLabeling\V1beta1\Instruction', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'ListAnnotatedDatasets' => [ 'pageStreaming' => [ @@ -72,6 +318,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getAnnotatedDatasets', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\DataLabeling\V1beta1\ListAnnotatedDatasetsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ListAnnotationSpecSets' => [ 'pageStreaming' => [ @@ -82,6 +338,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getAnnotationSpecSets', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\DataLabeling\V1beta1\ListAnnotationSpecSetsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ListDataItems' => [ 'pageStreaming' => [ @@ -92,6 +358,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getDataItems', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\DataLabeling\V1beta1\ListDataItemsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ListDatasets' => [ 'pageStreaming' => [ @@ -102,6 +378,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getDatasets', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\DataLabeling\V1beta1\ListDatasetsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ListEvaluationJobs' => [ 'pageStreaming' => [ @@ -112,6 +398,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getEvaluationJobs', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\DataLabeling\V1beta1\ListEvaluationJobsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ListExamples' => [ 'pageStreaming' => [ @@ -122,6 +418,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getExamples', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\DataLabeling\V1beta1\ListExamplesResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ListInstructions' => [ 'pageStreaming' => [ @@ -132,6 +438,40 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getInstructions', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\DataLabeling\V1beta1\ListInstructionsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'PauseEvaluationJob' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Protobuf\GPBEmpty', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'ResumeEvaluationJob' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Protobuf\GPBEmpty', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'SearchEvaluations' => [ 'pageStreaming' => [ @@ -142,6 +482,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getEvaluations', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\DataLabeling\V1beta1\SearchEvaluationsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'SearchExampleComparisons' => [ 'pageStreaming' => [ @@ -152,6 +502,40 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getExampleComparisons', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\DataLabeling\V1beta1\SearchExampleComparisonsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'UpdateEvaluationJob' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\DataLabeling\V1beta1\EvaluationJob', + 'headerParams' => [ + [ + 'keyName' => 'evaluation_job.name', + 'fieldAccessors' => [ + 'getEvaluationJob', + 'getName', + ], + ], + ], + ], + 'templateMap' => [ + 'annotatedDataset' => 'projects/{project}/datasets/{dataset}/annotatedDatasets/{annotated_dataset}', + 'annotationSpecSet' => 'projects/{project}/annotationSpecSets/{annotation_spec_set}', + 'dataItem' => 'projects/{project}/datasets/{dataset}/dataItems/{data_item}', + 'dataset' => 'projects/{project}/datasets/{dataset}', + 'evaluation' => 'projects/{project}/datasets/{dataset}/evaluations/{evaluation}', + 'evaluationJob' => 'projects/{project}/evaluationJobs/{evaluation_job}', + 'example' => 'projects/{project}/datasets/{dataset}/annotatedDatasets/{annotated_dataset}/examples/{example}', + 'instruction' => 'projects/{project}/instructions/{instruction}', + 'project' => 'projects/{project}', ], ], ], diff --git a/DataLabeling/tests/Unit/V1beta1/Client/DataLabelingServiceClientTest.php b/DataLabeling/tests/Unit/V1beta1/Client/DataLabelingServiceClientTest.php new file mode 100644 index 000000000000..85fe58cd0f3f --- /dev/null +++ b/DataLabeling/tests/Unit/V1beta1/Client/DataLabelingServiceClientTest.php @@ -0,0 +1,2943 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return DataLabelingServiceClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new DataLabelingServiceClient($options); + } + + /** @test */ + public function createAnnotationSpecSetTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $displayName = 'displayName1615086568'; + $description = 'description-1724546052'; + $expectedResponse = new AnnotationSpecSet(); + $expectedResponse->setName($name); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setDescription($description); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->projectName('[PROJECT]'); + $annotationSpecSet = new AnnotationSpecSet(); + $request = (new CreateAnnotationSpecSetRequest()) + ->setParent($formattedParent) + ->setAnnotationSpecSet($annotationSpecSet); + $response = $gapicClient->createAnnotationSpecSet($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datalabeling.v1beta1.DataLabelingService/CreateAnnotationSpecSet', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getAnnotationSpecSet(); + $this->assertProtobufEquals($annotationSpecSet, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createAnnotationSpecSetExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->projectName('[PROJECT]'); + $annotationSpecSet = new AnnotationSpecSet(); + $request = (new CreateAnnotationSpecSetRequest()) + ->setParent($formattedParent) + ->setAnnotationSpecSet($annotationSpecSet); + try { + $gapicClient->createAnnotationSpecSet($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createDatasetTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $displayName = 'displayName1615086568'; + $description = 'description-1724546052'; + $dataItemCount = 2014260376; + $expectedResponse = new Dataset(); + $expectedResponse->setName($name); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setDescription($description); + $expectedResponse->setDataItemCount($dataItemCount); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->projectName('[PROJECT]'); + $dataset = new Dataset(); + $request = (new CreateDatasetRequest()) + ->setParent($formattedParent) + ->setDataset($dataset); + $response = $gapicClient->createDataset($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datalabeling.v1beta1.DataLabelingService/CreateDataset', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getDataset(); + $this->assertProtobufEquals($dataset, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createDatasetExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->projectName('[PROJECT]'); + $dataset = new Dataset(); + $request = (new CreateDatasetRequest()) + ->setParent($formattedParent) + ->setDataset($dataset); + try { + $gapicClient->createDataset($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createEvaluationJobTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $description = 'description-1724546052'; + $schedule = 'schedule-697920873'; + $modelVersion = 'modelVersion-1669102142'; + $annotationSpecSet = 'annotationSpecSet1881405678'; + $labelMissingGroundTruth = false; + $expectedResponse = new EvaluationJob(); + $expectedResponse->setName($name); + $expectedResponse->setDescription($description); + $expectedResponse->setSchedule($schedule); + $expectedResponse->setModelVersion($modelVersion); + $expectedResponse->setAnnotationSpecSet($annotationSpecSet); + $expectedResponse->setLabelMissingGroundTruth($labelMissingGroundTruth); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->projectName('[PROJECT]'); + $job = new EvaluationJob(); + $request = (new CreateEvaluationJobRequest()) + ->setParent($formattedParent) + ->setJob($job); + $response = $gapicClient->createEvaluationJob($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datalabeling.v1beta1.DataLabelingService/CreateEvaluationJob', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getJob(); + $this->assertProtobufEquals($job, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createEvaluationJobExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->projectName('[PROJECT]'); + $job = new EvaluationJob(); + $request = (new CreateEvaluationJobRequest()) + ->setParent($formattedParent) + ->setJob($job); + try { + $gapicClient->createEvaluationJob($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createInstructionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/createInstructionTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $displayName = 'displayName1615086568'; + $description = 'description-1724546052'; + $expectedResponse = new Instruction(); + $expectedResponse->setName($name); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setDescription($description); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createInstructionTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->projectName('[PROJECT]'); + $instruction = new Instruction(); + $request = (new CreateInstructionRequest()) + ->setParent($formattedParent) + ->setInstruction($instruction); + $response = $gapicClient->createInstruction($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datalabeling.v1beta1.DataLabelingService/CreateInstruction', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getInstruction(); + $this->assertProtobufEquals($instruction, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createInstructionTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function createInstructionExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/createInstructionTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->projectName('[PROJECT]'); + $instruction = new Instruction(); + $request = (new CreateInstructionRequest()) + ->setParent($formattedParent) + ->setInstruction($instruction); + $response = $gapicClient->createInstruction($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createInstructionTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function deleteAnnotatedDatasetTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new GPBEmpty(); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->annotatedDatasetName('[PROJECT]', '[DATASET]', '[ANNOTATED_DATASET]'); + $request = (new DeleteAnnotatedDatasetRequest()) + ->setName($formattedName); + $gapicClient->deleteAnnotatedDataset($request); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datalabeling.v1beta1.DataLabelingService/DeleteAnnotatedDataset', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteAnnotatedDatasetExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->annotatedDatasetName('[PROJECT]', '[DATASET]', '[ANNOTATED_DATASET]'); + $request = (new DeleteAnnotatedDatasetRequest()) + ->setName($formattedName); + try { + $gapicClient->deleteAnnotatedDataset($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteAnnotationSpecSetTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new GPBEmpty(); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->annotationSpecSetName('[PROJECT]', '[ANNOTATION_SPEC_SET]'); + $request = (new DeleteAnnotationSpecSetRequest()) + ->setName($formattedName); + $gapicClient->deleteAnnotationSpecSet($request); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datalabeling.v1beta1.DataLabelingService/DeleteAnnotationSpecSet', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteAnnotationSpecSetExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->annotationSpecSetName('[PROJECT]', '[ANNOTATION_SPEC_SET]'); + $request = (new DeleteAnnotationSpecSetRequest()) + ->setName($formattedName); + try { + $gapicClient->deleteAnnotationSpecSet($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteDatasetTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new GPBEmpty(); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->datasetName('[PROJECT]', '[DATASET]'); + $request = (new DeleteDatasetRequest()) + ->setName($formattedName); + $gapicClient->deleteDataset($request); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datalabeling.v1beta1.DataLabelingService/DeleteDataset', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteDatasetExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->datasetName('[PROJECT]', '[DATASET]'); + $request = (new DeleteDatasetRequest()) + ->setName($formattedName); + try { + $gapicClient->deleteDataset($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteEvaluationJobTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new GPBEmpty(); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->evaluationJobName('[PROJECT]', '[EVALUATION_JOB]'); + $request = (new DeleteEvaluationJobRequest()) + ->setName($formattedName); + $gapicClient->deleteEvaluationJob($request); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datalabeling.v1beta1.DataLabelingService/DeleteEvaluationJob', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteEvaluationJobExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->evaluationJobName('[PROJECT]', '[EVALUATION_JOB]'); + $request = (new DeleteEvaluationJobRequest()) + ->setName($formattedName); + try { + $gapicClient->deleteEvaluationJob($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteInstructionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new GPBEmpty(); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->instructionName('[PROJECT]', '[INSTRUCTION]'); + $request = (new DeleteInstructionRequest()) + ->setName($formattedName); + $gapicClient->deleteInstruction($request); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datalabeling.v1beta1.DataLabelingService/DeleteInstruction', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteInstructionExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->instructionName('[PROJECT]', '[INSTRUCTION]'); + $request = (new DeleteInstructionRequest()) + ->setName($formattedName); + try { + $gapicClient->deleteInstruction($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function exportDataTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/exportDataTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $dataset = 'dataset1443214456'; + $totalCount = 407761836; + $exportCount = 529256252; + $expectedResponse = new ExportDataOperationResponse(); + $expectedResponse->setDataset($dataset); + $expectedResponse->setTotalCount($totalCount); + $expectedResponse->setExportCount($exportCount); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/exportDataTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->datasetName('[PROJECT]', '[DATASET]'); + $formattedAnnotatedDataset = $gapicClient->annotatedDatasetName('[PROJECT]', '[DATASET]', '[ANNOTATED_DATASET]'); + $outputConfig = new OutputConfig(); + $request = (new ExportDataRequest()) + ->setName($formattedName) + ->setAnnotatedDataset($formattedAnnotatedDataset) + ->setOutputConfig($outputConfig); + $response = $gapicClient->exportData($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datalabeling.v1beta1.DataLabelingService/ExportData', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $actualValue = $actualApiRequestObject->getAnnotatedDataset(); + $this->assertProtobufEquals($formattedAnnotatedDataset, $actualValue); + $actualValue = $actualApiRequestObject->getOutputConfig(); + $this->assertProtobufEquals($outputConfig, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/exportDataTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function exportDataExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/exportDataTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->datasetName('[PROJECT]', '[DATASET]'); + $formattedAnnotatedDataset = $gapicClient->annotatedDatasetName('[PROJECT]', '[DATASET]', '[ANNOTATED_DATASET]'); + $outputConfig = new OutputConfig(); + $request = (new ExportDataRequest()) + ->setName($formattedName) + ->setAnnotatedDataset($formattedAnnotatedDataset) + ->setOutputConfig($outputConfig); + $response = $gapicClient->exportData($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/exportDataTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function getAnnotatedDatasetTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $displayName = 'displayName1615086568'; + $description = 'description-1724546052'; + $exampleCount = 1517063674; + $completedExampleCount = 612567290; + $expectedResponse = new AnnotatedDataset(); + $expectedResponse->setName($name2); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setDescription($description); + $expectedResponse->setExampleCount($exampleCount); + $expectedResponse->setCompletedExampleCount($completedExampleCount); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->annotatedDatasetName('[PROJECT]', '[DATASET]', '[ANNOTATED_DATASET]'); + $request = (new GetAnnotatedDatasetRequest()) + ->setName($formattedName); + $response = $gapicClient->getAnnotatedDataset($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datalabeling.v1beta1.DataLabelingService/GetAnnotatedDataset', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getAnnotatedDatasetExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->annotatedDatasetName('[PROJECT]', '[DATASET]', '[ANNOTATED_DATASET]'); + $request = (new GetAnnotatedDatasetRequest()) + ->setName($formattedName); + try { + $gapicClient->getAnnotatedDataset($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getAnnotationSpecSetTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $displayName = 'displayName1615086568'; + $description = 'description-1724546052'; + $expectedResponse = new AnnotationSpecSet(); + $expectedResponse->setName($name2); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setDescription($description); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->annotationSpecSetName('[PROJECT]', '[ANNOTATION_SPEC_SET]'); + $request = (new GetAnnotationSpecSetRequest()) + ->setName($formattedName); + $response = $gapicClient->getAnnotationSpecSet($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datalabeling.v1beta1.DataLabelingService/GetAnnotationSpecSet', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getAnnotationSpecSetExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->annotationSpecSetName('[PROJECT]', '[ANNOTATION_SPEC_SET]'); + $request = (new GetAnnotationSpecSetRequest()) + ->setName($formattedName); + try { + $gapicClient->getAnnotationSpecSet($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getDataItemTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $expectedResponse = new DataItem(); + $expectedResponse->setName($name2); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->dataItemName('[PROJECT]', '[DATASET]', '[DATA_ITEM]'); + $request = (new GetDataItemRequest()) + ->setName($formattedName); + $response = $gapicClient->getDataItem($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datalabeling.v1beta1.DataLabelingService/GetDataItem', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getDataItemExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->dataItemName('[PROJECT]', '[DATASET]', '[DATA_ITEM]'); + $request = (new GetDataItemRequest()) + ->setName($formattedName); + try { + $gapicClient->getDataItem($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getDatasetTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $displayName = 'displayName1615086568'; + $description = 'description-1724546052'; + $dataItemCount = 2014260376; + $expectedResponse = new Dataset(); + $expectedResponse->setName($name2); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setDescription($description); + $expectedResponse->setDataItemCount($dataItemCount); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->datasetName('[PROJECT]', '[DATASET]'); + $request = (new GetDatasetRequest()) + ->setName($formattedName); + $response = $gapicClient->getDataset($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datalabeling.v1beta1.DataLabelingService/GetDataset', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getDatasetExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->datasetName('[PROJECT]', '[DATASET]'); + $request = (new GetDatasetRequest()) + ->setName($formattedName); + try { + $gapicClient->getDataset($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getEvaluationTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $evaluatedItemCount = 358077111; + $expectedResponse = new Evaluation(); + $expectedResponse->setName($name2); + $expectedResponse->setEvaluatedItemCount($evaluatedItemCount); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->evaluationName('[PROJECT]', '[DATASET]', '[EVALUATION]'); + $request = (new GetEvaluationRequest()) + ->setName($formattedName); + $response = $gapicClient->getEvaluation($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datalabeling.v1beta1.DataLabelingService/GetEvaluation', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getEvaluationExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->evaluationName('[PROJECT]', '[DATASET]', '[EVALUATION]'); + $request = (new GetEvaluationRequest()) + ->setName($formattedName); + try { + $gapicClient->getEvaluation($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getEvaluationJobTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $description = 'description-1724546052'; + $schedule = 'schedule-697920873'; + $modelVersion = 'modelVersion-1669102142'; + $annotationSpecSet = 'annotationSpecSet1881405678'; + $labelMissingGroundTruth = false; + $expectedResponse = new EvaluationJob(); + $expectedResponse->setName($name2); + $expectedResponse->setDescription($description); + $expectedResponse->setSchedule($schedule); + $expectedResponse->setModelVersion($modelVersion); + $expectedResponse->setAnnotationSpecSet($annotationSpecSet); + $expectedResponse->setLabelMissingGroundTruth($labelMissingGroundTruth); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->evaluationJobName('[PROJECT]', '[EVALUATION_JOB]'); + $request = (new GetEvaluationJobRequest()) + ->setName($formattedName); + $response = $gapicClient->getEvaluationJob($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datalabeling.v1beta1.DataLabelingService/GetEvaluationJob', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getEvaluationJobExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->evaluationJobName('[PROJECT]', '[EVALUATION_JOB]'); + $request = (new GetEvaluationJobRequest()) + ->setName($formattedName); + try { + $gapicClient->getEvaluationJob($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getExampleTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $expectedResponse = new Example(); + $expectedResponse->setName($name2); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->exampleName('[PROJECT]', '[DATASET]', '[ANNOTATED_DATASET]', '[EXAMPLE]'); + $request = (new GetExampleRequest()) + ->setName($formattedName); + $response = $gapicClient->getExample($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datalabeling.v1beta1.DataLabelingService/GetExample', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getExampleExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->exampleName('[PROJECT]', '[DATASET]', '[ANNOTATED_DATASET]', '[EXAMPLE]'); + $request = (new GetExampleRequest()) + ->setName($formattedName); + try { + $gapicClient->getExample($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getInstructionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $displayName = 'displayName1615086568'; + $description = 'description-1724546052'; + $expectedResponse = new Instruction(); + $expectedResponse->setName($name2); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setDescription($description); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->instructionName('[PROJECT]', '[INSTRUCTION]'); + $request = (new GetInstructionRequest()) + ->setName($formattedName); + $response = $gapicClient->getInstruction($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datalabeling.v1beta1.DataLabelingService/GetInstruction', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getInstructionExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->instructionName('[PROJECT]', '[INSTRUCTION]'); + $request = (new GetInstructionRequest()) + ->setName($formattedName); + try { + $gapicClient->getInstruction($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function importDataTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/importDataTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $dataset = 'dataset1443214456'; + $totalCount = 407761836; + $importCount = 1721296907; + $expectedResponse = new ImportDataOperationResponse(); + $expectedResponse->setDataset($dataset); + $expectedResponse->setTotalCount($totalCount); + $expectedResponse->setImportCount($importCount); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/importDataTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->datasetName('[PROJECT]', '[DATASET]'); + $inputConfig = new InputConfig(); + $request = (new ImportDataRequest()) + ->setName($formattedName) + ->setInputConfig($inputConfig); + $response = $gapicClient->importData($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datalabeling.v1beta1.DataLabelingService/ImportData', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $actualValue = $actualApiRequestObject->getInputConfig(); + $this->assertProtobufEquals($inputConfig, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/importDataTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function importDataExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/importDataTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->datasetName('[PROJECT]', '[DATASET]'); + $inputConfig = new InputConfig(); + $request = (new ImportDataRequest()) + ->setName($formattedName) + ->setInputConfig($inputConfig); + $response = $gapicClient->importData($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/importDataTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function labelImageTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/labelImageTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $displayName = 'displayName1615086568'; + $description = 'description-1724546052'; + $exampleCount = 1517063674; + $completedExampleCount = 612567290; + $expectedResponse = new AnnotatedDataset(); + $expectedResponse->setName($name); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setDescription($description); + $expectedResponse->setExampleCount($exampleCount); + $expectedResponse->setCompletedExampleCount($completedExampleCount); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/labelImageTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->datasetName('[PROJECT]', '[DATASET]'); + $basicConfig = new HumanAnnotationConfig(); + $basicConfigInstruction = 'basicConfigInstruction-1726324386'; + $basicConfig->setInstruction($basicConfigInstruction); + $basicConfigAnnotatedDatasetDisplayName = 'basicConfigAnnotatedDatasetDisplayName568435293'; + $basicConfig->setAnnotatedDatasetDisplayName($basicConfigAnnotatedDatasetDisplayName); + $feature = Feature::FEATURE_UNSPECIFIED; + $request = (new LabelImageRequest()) + ->setParent($formattedParent) + ->setBasicConfig($basicConfig) + ->setFeature($feature); + $response = $gapicClient->labelImage($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datalabeling.v1beta1.DataLabelingService/LabelImage', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getBasicConfig(); + $this->assertProtobufEquals($basicConfig, $actualValue); + $actualValue = $actualApiRequestObject->getFeature(); + $this->assertProtobufEquals($feature, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/labelImageTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function labelImageExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/labelImageTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->datasetName('[PROJECT]', '[DATASET]'); + $basicConfig = new HumanAnnotationConfig(); + $basicConfigInstruction = 'basicConfigInstruction-1726324386'; + $basicConfig->setInstruction($basicConfigInstruction); + $basicConfigAnnotatedDatasetDisplayName = 'basicConfigAnnotatedDatasetDisplayName568435293'; + $basicConfig->setAnnotatedDatasetDisplayName($basicConfigAnnotatedDatasetDisplayName); + $feature = Feature::FEATURE_UNSPECIFIED; + $request = (new LabelImageRequest()) + ->setParent($formattedParent) + ->setBasicConfig($basicConfig) + ->setFeature($feature); + $response = $gapicClient->labelImage($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/labelImageTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function labelTextTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/labelTextTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $displayName = 'displayName1615086568'; + $description = 'description-1724546052'; + $exampleCount = 1517063674; + $completedExampleCount = 612567290; + $expectedResponse = new AnnotatedDataset(); + $expectedResponse->setName($name); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setDescription($description); + $expectedResponse->setExampleCount($exampleCount); + $expectedResponse->setCompletedExampleCount($completedExampleCount); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/labelTextTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->datasetName('[PROJECT]', '[DATASET]'); + $basicConfig = new HumanAnnotationConfig(); + $basicConfigInstruction = 'basicConfigInstruction-1726324386'; + $basicConfig->setInstruction($basicConfigInstruction); + $basicConfigAnnotatedDatasetDisplayName = 'basicConfigAnnotatedDatasetDisplayName568435293'; + $basicConfig->setAnnotatedDatasetDisplayName($basicConfigAnnotatedDatasetDisplayName); + $feature = \Google\Cloud\DataLabeling\V1beta1\LabelTextRequest\Feature::FEATURE_UNSPECIFIED; + $request = (new LabelTextRequest()) + ->setParent($formattedParent) + ->setBasicConfig($basicConfig) + ->setFeature($feature); + $response = $gapicClient->labelText($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datalabeling.v1beta1.DataLabelingService/LabelText', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getBasicConfig(); + $this->assertProtobufEquals($basicConfig, $actualValue); + $actualValue = $actualApiRequestObject->getFeature(); + $this->assertProtobufEquals($feature, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/labelTextTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function labelTextExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/labelTextTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->datasetName('[PROJECT]', '[DATASET]'); + $basicConfig = new HumanAnnotationConfig(); + $basicConfigInstruction = 'basicConfigInstruction-1726324386'; + $basicConfig->setInstruction($basicConfigInstruction); + $basicConfigAnnotatedDatasetDisplayName = 'basicConfigAnnotatedDatasetDisplayName568435293'; + $basicConfig->setAnnotatedDatasetDisplayName($basicConfigAnnotatedDatasetDisplayName); + $feature = \Google\Cloud\DataLabeling\V1beta1\LabelTextRequest\Feature::FEATURE_UNSPECIFIED; + $request = (new LabelTextRequest()) + ->setParent($formattedParent) + ->setBasicConfig($basicConfig) + ->setFeature($feature); + $response = $gapicClient->labelText($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/labelTextTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function labelVideoTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/labelVideoTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $displayName = 'displayName1615086568'; + $description = 'description-1724546052'; + $exampleCount = 1517063674; + $completedExampleCount = 612567290; + $expectedResponse = new AnnotatedDataset(); + $expectedResponse->setName($name); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setDescription($description); + $expectedResponse->setExampleCount($exampleCount); + $expectedResponse->setCompletedExampleCount($completedExampleCount); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/labelVideoTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->datasetName('[PROJECT]', '[DATASET]'); + $basicConfig = new HumanAnnotationConfig(); + $basicConfigInstruction = 'basicConfigInstruction-1726324386'; + $basicConfig->setInstruction($basicConfigInstruction); + $basicConfigAnnotatedDatasetDisplayName = 'basicConfigAnnotatedDatasetDisplayName568435293'; + $basicConfig->setAnnotatedDatasetDisplayName($basicConfigAnnotatedDatasetDisplayName); + $feature = \Google\Cloud\DataLabeling\V1beta1\LabelVideoRequest\Feature::FEATURE_UNSPECIFIED; + $request = (new LabelVideoRequest()) + ->setParent($formattedParent) + ->setBasicConfig($basicConfig) + ->setFeature($feature); + $response = $gapicClient->labelVideo($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datalabeling.v1beta1.DataLabelingService/LabelVideo', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getBasicConfig(); + $this->assertProtobufEquals($basicConfig, $actualValue); + $actualValue = $actualApiRequestObject->getFeature(); + $this->assertProtobufEquals($feature, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/labelVideoTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function labelVideoExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/labelVideoTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->datasetName('[PROJECT]', '[DATASET]'); + $basicConfig = new HumanAnnotationConfig(); + $basicConfigInstruction = 'basicConfigInstruction-1726324386'; + $basicConfig->setInstruction($basicConfigInstruction); + $basicConfigAnnotatedDatasetDisplayName = 'basicConfigAnnotatedDatasetDisplayName568435293'; + $basicConfig->setAnnotatedDatasetDisplayName($basicConfigAnnotatedDatasetDisplayName); + $feature = \Google\Cloud\DataLabeling\V1beta1\LabelVideoRequest\Feature::FEATURE_UNSPECIFIED; + $request = (new LabelVideoRequest()) + ->setParent($formattedParent) + ->setBasicConfig($basicConfig) + ->setFeature($feature); + $response = $gapicClient->labelVideo($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/labelVideoTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function listAnnotatedDatasetsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $annotatedDatasetsElement = new AnnotatedDataset(); + $annotatedDatasets = [ + $annotatedDatasetsElement, + ]; + $expectedResponse = new ListAnnotatedDatasetsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setAnnotatedDatasets($annotatedDatasets); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->datasetName('[PROJECT]', '[DATASET]'); + $request = (new ListAnnotatedDatasetsRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listAnnotatedDatasets($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getAnnotatedDatasets()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datalabeling.v1beta1.DataLabelingService/ListAnnotatedDatasets', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listAnnotatedDatasetsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->datasetName('[PROJECT]', '[DATASET]'); + $request = (new ListAnnotatedDatasetsRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listAnnotatedDatasets($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listAnnotationSpecSetsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $annotationSpecSetsElement = new AnnotationSpecSet(); + $annotationSpecSets = [ + $annotationSpecSetsElement, + ]; + $expectedResponse = new ListAnnotationSpecSetsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setAnnotationSpecSets($annotationSpecSets); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->projectName('[PROJECT]'); + $request = (new ListAnnotationSpecSetsRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listAnnotationSpecSets($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getAnnotationSpecSets()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datalabeling.v1beta1.DataLabelingService/ListAnnotationSpecSets', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listAnnotationSpecSetsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->projectName('[PROJECT]'); + $request = (new ListAnnotationSpecSetsRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listAnnotationSpecSets($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listDataItemsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $dataItemsElement = new DataItem(); + $dataItems = [ + $dataItemsElement, + ]; + $expectedResponse = new ListDataItemsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setDataItems($dataItems); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->datasetName('[PROJECT]', '[DATASET]'); + $request = (new ListDataItemsRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listDataItems($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getDataItems()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datalabeling.v1beta1.DataLabelingService/ListDataItems', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listDataItemsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->datasetName('[PROJECT]', '[DATASET]'); + $request = (new ListDataItemsRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listDataItems($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listDatasetsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $datasetsElement = new Dataset(); + $datasets = [ + $datasetsElement, + ]; + $expectedResponse = new ListDatasetsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setDatasets($datasets); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->projectName('[PROJECT]'); + $request = (new ListDatasetsRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listDatasets($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getDatasets()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datalabeling.v1beta1.DataLabelingService/ListDatasets', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listDatasetsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->projectName('[PROJECT]'); + $request = (new ListDatasetsRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listDatasets($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listEvaluationJobsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $evaluationJobsElement = new EvaluationJob(); + $evaluationJobs = [ + $evaluationJobsElement, + ]; + $expectedResponse = new ListEvaluationJobsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setEvaluationJobs($evaluationJobs); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->projectName('[PROJECT]'); + $request = (new ListEvaluationJobsRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listEvaluationJobs($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getEvaluationJobs()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datalabeling.v1beta1.DataLabelingService/ListEvaluationJobs', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listEvaluationJobsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->projectName('[PROJECT]'); + $request = (new ListEvaluationJobsRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listEvaluationJobs($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listExamplesTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $examplesElement = new Example(); + $examples = [ + $examplesElement, + ]; + $expectedResponse = new ListExamplesResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setExamples($examples); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->annotatedDatasetName('[PROJECT]', '[DATASET]', '[ANNOTATED_DATASET]'); + $request = (new ListExamplesRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listExamples($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getExamples()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datalabeling.v1beta1.DataLabelingService/ListExamples', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listExamplesExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->annotatedDatasetName('[PROJECT]', '[DATASET]', '[ANNOTATED_DATASET]'); + $request = (new ListExamplesRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listExamples($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listInstructionsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $instructionsElement = new Instruction(); + $instructions = [ + $instructionsElement, + ]; + $expectedResponse = new ListInstructionsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setInstructions($instructions); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->projectName('[PROJECT]'); + $request = (new ListInstructionsRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listInstructions($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getInstructions()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datalabeling.v1beta1.DataLabelingService/ListInstructions', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listInstructionsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->projectName('[PROJECT]'); + $request = (new ListInstructionsRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listInstructions($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function pauseEvaluationJobTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new GPBEmpty(); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->evaluationJobName('[PROJECT]', '[EVALUATION_JOB]'); + $request = (new PauseEvaluationJobRequest()) + ->setName($formattedName); + $gapicClient->pauseEvaluationJob($request); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datalabeling.v1beta1.DataLabelingService/PauseEvaluationJob', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function pauseEvaluationJobExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->evaluationJobName('[PROJECT]', '[EVALUATION_JOB]'); + $request = (new PauseEvaluationJobRequest()) + ->setName($formattedName); + try { + $gapicClient->pauseEvaluationJob($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function resumeEvaluationJobTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new GPBEmpty(); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->evaluationJobName('[PROJECT]', '[EVALUATION_JOB]'); + $request = (new ResumeEvaluationJobRequest()) + ->setName($formattedName); + $gapicClient->resumeEvaluationJob($request); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datalabeling.v1beta1.DataLabelingService/ResumeEvaluationJob', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function resumeEvaluationJobExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->evaluationJobName('[PROJECT]', '[EVALUATION_JOB]'); + $request = (new ResumeEvaluationJobRequest()) + ->setName($formattedName); + try { + $gapicClient->resumeEvaluationJob($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function searchEvaluationsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $evaluationsElement = new Evaluation(); + $evaluations = [ + $evaluationsElement, + ]; + $expectedResponse = new SearchEvaluationsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setEvaluations($evaluations); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->evaluationName('[PROJECT]', '[DATASET]', '[EVALUATION]'); + $request = (new SearchEvaluationsRequest()) + ->setParent($formattedParent); + $response = $gapicClient->searchEvaluations($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getEvaluations()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datalabeling.v1beta1.DataLabelingService/SearchEvaluations', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function searchEvaluationsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->evaluationName('[PROJECT]', '[DATASET]', '[EVALUATION]'); + $request = (new SearchEvaluationsRequest()) + ->setParent($formattedParent); + try { + $gapicClient->searchEvaluations($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function searchExampleComparisonsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $exampleComparisonsElement = new ExampleComparison(); + $exampleComparisons = [ + $exampleComparisonsElement, + ]; + $expectedResponse = new SearchExampleComparisonsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setExampleComparisons($exampleComparisons); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->evaluationName('[PROJECT]', '[DATASET]', '[EVALUATION]'); + $request = (new SearchExampleComparisonsRequest()) + ->setParent($formattedParent); + $response = $gapicClient->searchExampleComparisons($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getExampleComparisons()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datalabeling.v1beta1.DataLabelingService/SearchExampleComparisons', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function searchExampleComparisonsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->evaluationName('[PROJECT]', '[DATASET]', '[EVALUATION]'); + $request = (new SearchExampleComparisonsRequest()) + ->setParent($formattedParent); + try { + $gapicClient->searchExampleComparisons($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function updateEvaluationJobTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $description = 'description-1724546052'; + $schedule = 'schedule-697920873'; + $modelVersion = 'modelVersion-1669102142'; + $annotationSpecSet = 'annotationSpecSet1881405678'; + $labelMissingGroundTruth = false; + $expectedResponse = new EvaluationJob(); + $expectedResponse->setName($name); + $expectedResponse->setDescription($description); + $expectedResponse->setSchedule($schedule); + $expectedResponse->setModelVersion($modelVersion); + $expectedResponse->setAnnotationSpecSet($annotationSpecSet); + $expectedResponse->setLabelMissingGroundTruth($labelMissingGroundTruth); + $transport->addResponse($expectedResponse); + // Mock request + $evaluationJob = new EvaluationJob(); + $request = (new UpdateEvaluationJobRequest()) + ->setEvaluationJob($evaluationJob); + $response = $gapicClient->updateEvaluationJob($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datalabeling.v1beta1.DataLabelingService/UpdateEvaluationJob', $actualFuncCall); + $actualValue = $actualRequestObject->getEvaluationJob(); + $this->assertProtobufEquals($evaluationJob, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function updateEvaluationJobExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $evaluationJob = new EvaluationJob(); + $request = (new UpdateEvaluationJobRequest()) + ->setEvaluationJob($evaluationJob); + try { + $gapicClient->updateEvaluationJob($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createAnnotationSpecSetAsyncTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $displayName = 'displayName1615086568'; + $description = 'description-1724546052'; + $expectedResponse = new AnnotationSpecSet(); + $expectedResponse->setName($name); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setDescription($description); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->projectName('[PROJECT]'); + $annotationSpecSet = new AnnotationSpecSet(); + $request = (new CreateAnnotationSpecSetRequest()) + ->setParent($formattedParent) + ->setAnnotationSpecSet($annotationSpecSet); + $response = $gapicClient->createAnnotationSpecSetAsync($request)->wait(); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.datalabeling.v1beta1.DataLabelingService/CreateAnnotationSpecSet', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getAnnotationSpecSet(); + $this->assertProtobufEquals($annotationSpecSet, $actualValue); + $this->assertTrue($transport->isExhausted()); + } +} diff --git a/Dataflow/samples/V1beta3/FlexTemplatesServiceClient/launch_flex_template.php b/Dataflow/samples/V1beta3/FlexTemplatesServiceClient/launch_flex_template.php index 8f9e12c76ba1..97dbc8d2843d 100644 --- a/Dataflow/samples/V1beta3/FlexTemplatesServiceClient/launch_flex_template.php +++ b/Dataflow/samples/V1beta3/FlexTemplatesServiceClient/launch_flex_template.php @@ -24,7 +24,8 @@ // [START dataflow_v1beta3_generated_FlexTemplatesService_LaunchFlexTemplate_sync] use Google\ApiCore\ApiException; -use Google\Cloud\Dataflow\V1beta3\FlexTemplatesServiceClient; +use Google\Cloud\Dataflow\V1beta3\Client\FlexTemplatesServiceClient; +use Google\Cloud\Dataflow\V1beta3\LaunchFlexTemplateRequest; use Google\Cloud\Dataflow\V1beta3\LaunchFlexTemplateResponse; /** @@ -41,10 +42,13 @@ function launch_flex_template_sample(): void // Create a client. $flexTemplatesServiceClient = new FlexTemplatesServiceClient(); + // Prepare the request message. + $request = new LaunchFlexTemplateRequest(); + // Call the API and handle any network failures. try { /** @var LaunchFlexTemplateResponse $response */ - $response = $flexTemplatesServiceClient->launchFlexTemplate(); + $response = $flexTemplatesServiceClient->launchFlexTemplate($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/Dataflow/samples/V1beta3/JobsV1Beta3Client/aggregated_list_jobs.php b/Dataflow/samples/V1beta3/JobsV1Beta3Client/aggregated_list_jobs.php index 70a3b0ba21f4..4322ced6701b 100644 --- a/Dataflow/samples/V1beta3/JobsV1Beta3Client/aggregated_list_jobs.php +++ b/Dataflow/samples/V1beta3/JobsV1Beta3Client/aggregated_list_jobs.php @@ -25,8 +25,9 @@ // [START dataflow_v1beta3_generated_JobsV1Beta3_AggregatedListJobs_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; +use Google\Cloud\Dataflow\V1beta3\Client\JobsV1Beta3Client; use Google\Cloud\Dataflow\V1beta3\Job; -use Google\Cloud\Dataflow\V1beta3\JobsV1Beta3Client; +use Google\Cloud\Dataflow\V1beta3\ListJobsRequest; /** * List the jobs of a project across all regions. @@ -42,10 +43,13 @@ function aggregated_list_jobs_sample(): void // Create a client. $jobsV1Beta3Client = new JobsV1Beta3Client(); + // Prepare the request message. + $request = new ListJobsRequest(); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $jobsV1Beta3Client->aggregatedListJobs(); + $response = $jobsV1Beta3Client->aggregatedListJobs($request); /** @var Job $element */ foreach ($response as $element) { diff --git a/Dataflow/samples/V1beta3/JobsV1Beta3Client/check_active_jobs.php b/Dataflow/samples/V1beta3/JobsV1Beta3Client/check_active_jobs.php index def664221fe3..bc9fc4e85e7e 100644 --- a/Dataflow/samples/V1beta3/JobsV1Beta3Client/check_active_jobs.php +++ b/Dataflow/samples/V1beta3/JobsV1Beta3Client/check_active_jobs.php @@ -24,8 +24,9 @@ // [START dataflow_v1beta3_generated_JobsV1Beta3_CheckActiveJobs_sync] use Google\ApiCore\ApiException; +use Google\Cloud\Dataflow\V1beta3\CheckActiveJobsRequest; use Google\Cloud\Dataflow\V1beta3\CheckActiveJobsResponse; -use Google\Cloud\Dataflow\V1beta3\JobsV1Beta3Client; +use Google\Cloud\Dataflow\V1beta3\Client\JobsV1Beta3Client; /** * Check for existence of active jobs in the given project across all regions. @@ -41,10 +42,13 @@ function check_active_jobs_sample(): void // Create a client. $jobsV1Beta3Client = new JobsV1Beta3Client(); + // Prepare the request message. + $request = new CheckActiveJobsRequest(); + // Call the API and handle any network failures. try { /** @var CheckActiveJobsResponse $response */ - $response = $jobsV1Beta3Client->checkActiveJobs(); + $response = $jobsV1Beta3Client->checkActiveJobs($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/Dataflow/samples/V1beta3/JobsV1Beta3Client/create_job.php b/Dataflow/samples/V1beta3/JobsV1Beta3Client/create_job.php index 91ac3e42b2be..07146dcd10b7 100644 --- a/Dataflow/samples/V1beta3/JobsV1Beta3Client/create_job.php +++ b/Dataflow/samples/V1beta3/JobsV1Beta3Client/create_job.php @@ -24,8 +24,9 @@ // [START dataflow_v1beta3_generated_JobsV1Beta3_CreateJob_sync] use Google\ApiCore\ApiException; +use Google\Cloud\Dataflow\V1beta3\Client\JobsV1Beta3Client; +use Google\Cloud\Dataflow\V1beta3\CreateJobRequest; use Google\Cloud\Dataflow\V1beta3\Job; -use Google\Cloud\Dataflow\V1beta3\JobsV1Beta3Client; /** * Creates a Cloud Dataflow job. @@ -47,10 +48,13 @@ function create_job_sample(): void // Create a client. $jobsV1Beta3Client = new JobsV1Beta3Client(); + // Prepare the request message. + $request = new CreateJobRequest(); + // Call the API and handle any network failures. try { /** @var Job $response */ - $response = $jobsV1Beta3Client->createJob(); + $response = $jobsV1Beta3Client->createJob($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/Dataflow/samples/V1beta3/JobsV1Beta3Client/get_job.php b/Dataflow/samples/V1beta3/JobsV1Beta3Client/get_job.php index b947155fc30e..71404ef478e0 100644 --- a/Dataflow/samples/V1beta3/JobsV1Beta3Client/get_job.php +++ b/Dataflow/samples/V1beta3/JobsV1Beta3Client/get_job.php @@ -24,8 +24,9 @@ // [START dataflow_v1beta3_generated_JobsV1Beta3_GetJob_sync] use Google\ApiCore\ApiException; +use Google\Cloud\Dataflow\V1beta3\Client\JobsV1Beta3Client; +use Google\Cloud\Dataflow\V1beta3\GetJobRequest; use Google\Cloud\Dataflow\V1beta3\Job; -use Google\Cloud\Dataflow\V1beta3\JobsV1Beta3Client; /** * Gets the state of the specified Cloud Dataflow job. @@ -47,10 +48,13 @@ function get_job_sample(): void // Create a client. $jobsV1Beta3Client = new JobsV1Beta3Client(); + // Prepare the request message. + $request = new GetJobRequest(); + // Call the API and handle any network failures. try { /** @var Job $response */ - $response = $jobsV1Beta3Client->getJob(); + $response = $jobsV1Beta3Client->getJob($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/Dataflow/samples/V1beta3/JobsV1Beta3Client/list_jobs.php b/Dataflow/samples/V1beta3/JobsV1Beta3Client/list_jobs.php index d8d109e94a06..75b2ba00ccb2 100644 --- a/Dataflow/samples/V1beta3/JobsV1Beta3Client/list_jobs.php +++ b/Dataflow/samples/V1beta3/JobsV1Beta3Client/list_jobs.php @@ -25,8 +25,9 @@ // [START dataflow_v1beta3_generated_JobsV1Beta3_ListJobs_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; +use Google\Cloud\Dataflow\V1beta3\Client\JobsV1Beta3Client; use Google\Cloud\Dataflow\V1beta3\Job; -use Google\Cloud\Dataflow\V1beta3\JobsV1Beta3Client; +use Google\Cloud\Dataflow\V1beta3\ListJobsRequest; /** * List the jobs of a project. @@ -49,10 +50,13 @@ function list_jobs_sample(): void // Create a client. $jobsV1Beta3Client = new JobsV1Beta3Client(); + // Prepare the request message. + $request = new ListJobsRequest(); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $jobsV1Beta3Client->listJobs(); + $response = $jobsV1Beta3Client->listJobs($request); /** @var Job $element */ foreach ($response as $element) { diff --git a/Dataflow/samples/V1beta3/JobsV1Beta3Client/snapshot_job.php b/Dataflow/samples/V1beta3/JobsV1Beta3Client/snapshot_job.php index edb37112b527..6f542c0e7d08 100644 --- a/Dataflow/samples/V1beta3/JobsV1Beta3Client/snapshot_job.php +++ b/Dataflow/samples/V1beta3/JobsV1Beta3Client/snapshot_job.php @@ -24,8 +24,9 @@ // [START dataflow_v1beta3_generated_JobsV1Beta3_SnapshotJob_sync] use Google\ApiCore\ApiException; -use Google\Cloud\Dataflow\V1beta3\JobsV1Beta3Client; +use Google\Cloud\Dataflow\V1beta3\Client\JobsV1Beta3Client; use Google\Cloud\Dataflow\V1beta3\Snapshot; +use Google\Cloud\Dataflow\V1beta3\SnapshotJobRequest; /** * Snapshot the state of a streaming job. @@ -41,10 +42,13 @@ function snapshot_job_sample(): void // Create a client. $jobsV1Beta3Client = new JobsV1Beta3Client(); + // Prepare the request message. + $request = new SnapshotJobRequest(); + // Call the API and handle any network failures. try { /** @var Snapshot $response */ - $response = $jobsV1Beta3Client->snapshotJob(); + $response = $jobsV1Beta3Client->snapshotJob($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/Dataflow/samples/V1beta3/JobsV1Beta3Client/update_job.php b/Dataflow/samples/V1beta3/JobsV1Beta3Client/update_job.php index 616d31441267..4f08f4bd9a23 100644 --- a/Dataflow/samples/V1beta3/JobsV1Beta3Client/update_job.php +++ b/Dataflow/samples/V1beta3/JobsV1Beta3Client/update_job.php @@ -24,8 +24,9 @@ // [START dataflow_v1beta3_generated_JobsV1Beta3_UpdateJob_sync] use Google\ApiCore\ApiException; +use Google\Cloud\Dataflow\V1beta3\Client\JobsV1Beta3Client; use Google\Cloud\Dataflow\V1beta3\Job; -use Google\Cloud\Dataflow\V1beta3\JobsV1Beta3Client; +use Google\Cloud\Dataflow\V1beta3\UpdateJobRequest; /** * Updates the state of an existing Cloud Dataflow job. @@ -47,10 +48,13 @@ function update_job_sample(): void // Create a client. $jobsV1Beta3Client = new JobsV1Beta3Client(); + // Prepare the request message. + $request = new UpdateJobRequest(); + // Call the API and handle any network failures. try { /** @var Job $response */ - $response = $jobsV1Beta3Client->updateJob(); + $response = $jobsV1Beta3Client->updateJob($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/Dataflow/samples/V1beta3/MessagesV1Beta3Client/list_job_messages.php b/Dataflow/samples/V1beta3/MessagesV1Beta3Client/list_job_messages.php index ab04eb4f8a67..16f7060f7514 100644 --- a/Dataflow/samples/V1beta3/MessagesV1Beta3Client/list_job_messages.php +++ b/Dataflow/samples/V1beta3/MessagesV1Beta3Client/list_job_messages.php @@ -25,8 +25,9 @@ // [START dataflow_v1beta3_generated_MessagesV1Beta3_ListJobMessages_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; +use Google\Cloud\Dataflow\V1beta3\Client\MessagesV1Beta3Client; use Google\Cloud\Dataflow\V1beta3\JobMessage; -use Google\Cloud\Dataflow\V1beta3\MessagesV1Beta3Client; +use Google\Cloud\Dataflow\V1beta3\ListJobMessagesRequest; /** * Request the job status. @@ -48,10 +49,13 @@ function list_job_messages_sample(): void // Create a client. $messagesV1Beta3Client = new MessagesV1Beta3Client(); + // Prepare the request message. + $request = new ListJobMessagesRequest(); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $messagesV1Beta3Client->listJobMessages(); + $response = $messagesV1Beta3Client->listJobMessages($request); /** @var JobMessage $element */ foreach ($response as $element) { diff --git a/Dataflow/samples/V1beta3/MetricsV1Beta3Client/get_job_execution_details.php b/Dataflow/samples/V1beta3/MetricsV1Beta3Client/get_job_execution_details.php index 48cdbc5f4aec..c74acf17fac6 100644 --- a/Dataflow/samples/V1beta3/MetricsV1Beta3Client/get_job_execution_details.php +++ b/Dataflow/samples/V1beta3/MetricsV1Beta3Client/get_job_execution_details.php @@ -25,7 +25,8 @@ // [START dataflow_v1beta3_generated_MetricsV1Beta3_GetJobExecutionDetails_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; -use Google\Cloud\Dataflow\V1beta3\MetricsV1Beta3Client; +use Google\Cloud\Dataflow\V1beta3\Client\MetricsV1Beta3Client; +use Google\Cloud\Dataflow\V1beta3\GetJobExecutionDetailsRequest; use Google\Cloud\Dataflow\V1beta3\StageSummary; /** @@ -44,10 +45,13 @@ function get_job_execution_details_sample(): void // Create a client. $metricsV1Beta3Client = new MetricsV1Beta3Client(); + // Prepare the request message. + $request = new GetJobExecutionDetailsRequest(); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $metricsV1Beta3Client->getJobExecutionDetails(); + $response = $metricsV1Beta3Client->getJobExecutionDetails($request); /** @var StageSummary $element */ foreach ($response as $element) { diff --git a/Dataflow/samples/V1beta3/MetricsV1Beta3Client/get_job_metrics.php b/Dataflow/samples/V1beta3/MetricsV1Beta3Client/get_job_metrics.php index 5cf134e3db76..681decd41792 100644 --- a/Dataflow/samples/V1beta3/MetricsV1Beta3Client/get_job_metrics.php +++ b/Dataflow/samples/V1beta3/MetricsV1Beta3Client/get_job_metrics.php @@ -24,8 +24,9 @@ // [START dataflow_v1beta3_generated_MetricsV1Beta3_GetJobMetrics_sync] use Google\ApiCore\ApiException; +use Google\Cloud\Dataflow\V1beta3\Client\MetricsV1Beta3Client; +use Google\Cloud\Dataflow\V1beta3\GetJobMetricsRequest; use Google\Cloud\Dataflow\V1beta3\JobMetrics; -use Google\Cloud\Dataflow\V1beta3\MetricsV1Beta3Client; /** * Request the job status. @@ -47,10 +48,13 @@ function get_job_metrics_sample(): void // Create a client. $metricsV1Beta3Client = new MetricsV1Beta3Client(); + // Prepare the request message. + $request = new GetJobMetricsRequest(); + // Call the API and handle any network failures. try { /** @var JobMetrics $response */ - $response = $metricsV1Beta3Client->getJobMetrics(); + $response = $metricsV1Beta3Client->getJobMetrics($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/Dataflow/samples/V1beta3/MetricsV1Beta3Client/get_stage_execution_details.php b/Dataflow/samples/V1beta3/MetricsV1Beta3Client/get_stage_execution_details.php index 555a59df76df..285bc8d788c5 100644 --- a/Dataflow/samples/V1beta3/MetricsV1Beta3Client/get_stage_execution_details.php +++ b/Dataflow/samples/V1beta3/MetricsV1Beta3Client/get_stage_execution_details.php @@ -25,7 +25,8 @@ // [START dataflow_v1beta3_generated_MetricsV1Beta3_GetStageExecutionDetails_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; -use Google\Cloud\Dataflow\V1beta3\MetricsV1Beta3Client; +use Google\Cloud\Dataflow\V1beta3\Client\MetricsV1Beta3Client; +use Google\Cloud\Dataflow\V1beta3\GetStageExecutionDetailsRequest; use Google\Cloud\Dataflow\V1beta3\WorkerDetails; /** @@ -45,10 +46,13 @@ function get_stage_execution_details_sample(): void // Create a client. $metricsV1Beta3Client = new MetricsV1Beta3Client(); + // Prepare the request message. + $request = new GetStageExecutionDetailsRequest(); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $metricsV1Beta3Client->getStageExecutionDetails(); + $response = $metricsV1Beta3Client->getStageExecutionDetails($request); /** @var WorkerDetails $element */ foreach ($response as $element) { diff --git a/Dataflow/samples/V1beta3/SnapshotsV1Beta3Client/delete_snapshot.php b/Dataflow/samples/V1beta3/SnapshotsV1Beta3Client/delete_snapshot.php index 5272f00956fb..467dedbe6600 100644 --- a/Dataflow/samples/V1beta3/SnapshotsV1Beta3Client/delete_snapshot.php +++ b/Dataflow/samples/V1beta3/SnapshotsV1Beta3Client/delete_snapshot.php @@ -24,8 +24,9 @@ // [START dataflow_v1beta3_generated_SnapshotsV1Beta3_DeleteSnapshot_sync] use Google\ApiCore\ApiException; +use Google\Cloud\Dataflow\V1beta3\Client\SnapshotsV1Beta3Client; +use Google\Cloud\Dataflow\V1beta3\DeleteSnapshotRequest; use Google\Cloud\Dataflow\V1beta3\DeleteSnapshotResponse; -use Google\Cloud\Dataflow\V1beta3\SnapshotsV1Beta3Client; /** * Deletes a snapshot. @@ -41,10 +42,13 @@ function delete_snapshot_sample(): void // Create a client. $snapshotsV1Beta3Client = new SnapshotsV1Beta3Client(); + // Prepare the request message. + $request = new DeleteSnapshotRequest(); + // Call the API and handle any network failures. try { /** @var DeleteSnapshotResponse $response */ - $response = $snapshotsV1Beta3Client->deleteSnapshot(); + $response = $snapshotsV1Beta3Client->deleteSnapshot($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/Dataflow/samples/V1beta3/SnapshotsV1Beta3Client/get_snapshot.php b/Dataflow/samples/V1beta3/SnapshotsV1Beta3Client/get_snapshot.php index f65ec68a8fd2..6f28b4ff6a61 100644 --- a/Dataflow/samples/V1beta3/SnapshotsV1Beta3Client/get_snapshot.php +++ b/Dataflow/samples/V1beta3/SnapshotsV1Beta3Client/get_snapshot.php @@ -24,8 +24,9 @@ // [START dataflow_v1beta3_generated_SnapshotsV1Beta3_GetSnapshot_sync] use Google\ApiCore\ApiException; +use Google\Cloud\Dataflow\V1beta3\Client\SnapshotsV1Beta3Client; +use Google\Cloud\Dataflow\V1beta3\GetSnapshotRequest; use Google\Cloud\Dataflow\V1beta3\Snapshot; -use Google\Cloud\Dataflow\V1beta3\SnapshotsV1Beta3Client; /** * Gets information about a snapshot. @@ -41,10 +42,13 @@ function get_snapshot_sample(): void // Create a client. $snapshotsV1Beta3Client = new SnapshotsV1Beta3Client(); + // Prepare the request message. + $request = new GetSnapshotRequest(); + // Call the API and handle any network failures. try { /** @var Snapshot $response */ - $response = $snapshotsV1Beta3Client->getSnapshot(); + $response = $snapshotsV1Beta3Client->getSnapshot($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/Dataflow/samples/V1beta3/SnapshotsV1Beta3Client/list_snapshots.php b/Dataflow/samples/V1beta3/SnapshotsV1Beta3Client/list_snapshots.php index 4b5839939e50..31a8cb6786ec 100644 --- a/Dataflow/samples/V1beta3/SnapshotsV1Beta3Client/list_snapshots.php +++ b/Dataflow/samples/V1beta3/SnapshotsV1Beta3Client/list_snapshots.php @@ -24,8 +24,9 @@ // [START dataflow_v1beta3_generated_SnapshotsV1Beta3_ListSnapshots_sync] use Google\ApiCore\ApiException; +use Google\Cloud\Dataflow\V1beta3\Client\SnapshotsV1Beta3Client; +use Google\Cloud\Dataflow\V1beta3\ListSnapshotsRequest; use Google\Cloud\Dataflow\V1beta3\ListSnapshotsResponse; -use Google\Cloud\Dataflow\V1beta3\SnapshotsV1Beta3Client; /** * Lists snapshots. @@ -41,10 +42,13 @@ function list_snapshots_sample(): void // Create a client. $snapshotsV1Beta3Client = new SnapshotsV1Beta3Client(); + // Prepare the request message. + $request = new ListSnapshotsRequest(); + // Call the API and handle any network failures. try { /** @var ListSnapshotsResponse $response */ - $response = $snapshotsV1Beta3Client->listSnapshots(); + $response = $snapshotsV1Beta3Client->listSnapshots($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/Dataflow/samples/V1beta3/TemplatesServiceClient/create_job_from_template.php b/Dataflow/samples/V1beta3/TemplatesServiceClient/create_job_from_template.php index 2012a20bf51c..b87e9b36a1d1 100644 --- a/Dataflow/samples/V1beta3/TemplatesServiceClient/create_job_from_template.php +++ b/Dataflow/samples/V1beta3/TemplatesServiceClient/create_job_from_template.php @@ -24,8 +24,9 @@ // [START dataflow_v1beta3_generated_TemplatesService_CreateJobFromTemplate_sync] use Google\ApiCore\ApiException; +use Google\Cloud\Dataflow\V1beta3\Client\TemplatesServiceClient; +use Google\Cloud\Dataflow\V1beta3\CreateJobFromTemplateRequest; use Google\Cloud\Dataflow\V1beta3\Job; -use Google\Cloud\Dataflow\V1beta3\TemplatesServiceClient; /** * Creates a Cloud Dataflow job from a template. @@ -41,10 +42,13 @@ function create_job_from_template_sample(): void // Create a client. $templatesServiceClient = new TemplatesServiceClient(); + // Prepare the request message. + $request = new CreateJobFromTemplateRequest(); + // Call the API and handle any network failures. try { /** @var Job $response */ - $response = $templatesServiceClient->createJobFromTemplate(); + $response = $templatesServiceClient->createJobFromTemplate($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/Dataflow/samples/V1beta3/TemplatesServiceClient/get_template.php b/Dataflow/samples/V1beta3/TemplatesServiceClient/get_template.php index e134c685b868..46e32eabace6 100644 --- a/Dataflow/samples/V1beta3/TemplatesServiceClient/get_template.php +++ b/Dataflow/samples/V1beta3/TemplatesServiceClient/get_template.php @@ -24,8 +24,9 @@ // [START dataflow_v1beta3_generated_TemplatesService_GetTemplate_sync] use Google\ApiCore\ApiException; +use Google\Cloud\Dataflow\V1beta3\Client\TemplatesServiceClient; +use Google\Cloud\Dataflow\V1beta3\GetTemplateRequest; use Google\Cloud\Dataflow\V1beta3\GetTemplateResponse; -use Google\Cloud\Dataflow\V1beta3\TemplatesServiceClient; /** * Get the template associated with a template. @@ -41,10 +42,13 @@ function get_template_sample(): void // Create a client. $templatesServiceClient = new TemplatesServiceClient(); + // Prepare the request message. + $request = new GetTemplateRequest(); + // Call the API and handle any network failures. try { /** @var GetTemplateResponse $response */ - $response = $templatesServiceClient->getTemplate(); + $response = $templatesServiceClient->getTemplate($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/Dataflow/samples/V1beta3/TemplatesServiceClient/launch_template.php b/Dataflow/samples/V1beta3/TemplatesServiceClient/launch_template.php index 040a60aa0ad0..d08fb198d649 100644 --- a/Dataflow/samples/V1beta3/TemplatesServiceClient/launch_template.php +++ b/Dataflow/samples/V1beta3/TemplatesServiceClient/launch_template.php @@ -24,8 +24,9 @@ // [START dataflow_v1beta3_generated_TemplatesService_LaunchTemplate_sync] use Google\ApiCore\ApiException; +use Google\Cloud\Dataflow\V1beta3\Client\TemplatesServiceClient; +use Google\Cloud\Dataflow\V1beta3\LaunchTemplateRequest; use Google\Cloud\Dataflow\V1beta3\LaunchTemplateResponse; -use Google\Cloud\Dataflow\V1beta3\TemplatesServiceClient; /** * Launch a template. @@ -41,10 +42,13 @@ function launch_template_sample(): void // Create a client. $templatesServiceClient = new TemplatesServiceClient(); + // Prepare the request message. + $request = new LaunchTemplateRequest(); + // Call the API and handle any network failures. try { /** @var LaunchTemplateResponse $response */ - $response = $templatesServiceClient->launchTemplate(); + $response = $templatesServiceClient->launchTemplate($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/Dataflow/src/V1beta3/Client/BaseClient/FlexTemplatesServiceBaseClient.php b/Dataflow/src/V1beta3/Client/BaseClient/FlexTemplatesServiceBaseClient.php new file mode 100644 index 000000000000..e12f1982001d --- /dev/null +++ b/Dataflow/src/V1beta3/Client/BaseClient/FlexTemplatesServiceBaseClient.php @@ -0,0 +1,195 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/flex_templates_service_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/flex_templates_service_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/flex_templates_service_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/flex_templates_service_rest_client_config.php', + ], + ], + ]; + } + + /** + * Constructor. + * + * @param array $options { + * Optional. Options for configuring the service API wrapper. + * + * @type string $apiEndpoint + * The address of the API remote host. May optionally include the port, formatted + * as ":". Default 'dataflow.googleapis.com:443'. + * @type string|array|FetchAuthTokenInterface|CredentialsWrapper $credentials + * The credentials to be used by the client to authorize API calls. This option + * accepts either a path to a credentials file, or a decoded credentials file as a + * PHP array. + * *Advanced usage*: In addition, this option can also accept a pre-constructed + * {@see \Google\Auth\FetchAuthTokenInterface} object or + * {@see \Google\ApiCore\CredentialsWrapper} object. Note that when one of these + * objects are provided, any settings in $credentialsConfig will be ignored. + * @type array $credentialsConfig + * Options used to configure credentials, including auth token caching, for the + * client. For a full list of supporting configuration options, see + * {@see \Google\ApiCore\CredentialsWrapper::build()} . + * @type bool $disableRetries + * Determines whether or not retries defined by the client configuration should be + * disabled. Defaults to `false`. + * @type string|array $clientConfig + * Client method configuration, including retry settings. This option can be either + * a path to a JSON file, or a PHP array containing the decoded JSON data. By + * default this settings points to the default client config file, which is + * provided in the resources folder. + * @type string|TransportInterface $transport + * The transport used for executing network requests. May be either the string + * `rest` or `grpc`. Defaults to `grpc` if gRPC support is detected on the system. + * *Advanced usage*: Additionally, it is possible to pass in an already + * instantiated {@see \Google\ApiCore\Transport\TransportInterface} object. Note + * that when this object is provided, any settings in $transportConfig, and any + * $apiEndpoint setting, will be ignored. + * @type array $transportConfig + * Configuration options that will be used to construct the transport. Options for + * each supported transport type should be passed in a key for that transport. For + * example: + * $transportConfig = [ + * 'grpc' => [...], + * 'rest' => [...], + * ]; + * See the {@see \Google\ApiCore\Transport\GrpcTransport::build()} and + * {@see \Google\ApiCore\Transport\RestTransport::build()} methods for the + * supported options. + * @type callable $clientCertSource + * A callable which returns the client cert as a string. This can be used to + * provide a certificate and private key to the transport layer for mTLS. + * } + * + * @throws ValidationException + * + * @experimental + */ + public function __construct(array $options = []) + { + $clientOptions = $this->buildClientOptions($options); + $this->setClientOptions($clientOptions); + } + + /** Handles execution of the async variants for each documented method. */ + public function __call($method, $args) + { + if (substr($method, -5) !== 'Async') { + trigger_error('Call to undefined method ' . __CLASS__ . "::$method()", E_USER_ERROR); + } + + array_unshift($args, substr($method, 0, -5)); + return call_user_func_array([$this, 'startAsyncCall'], $args); + } + + /** + * Launch a job with a FlexTemplate. + * + * The async variant is {@see self::launchFlexTemplateAsync()} . + * + * @param LaunchFlexTemplateRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return LaunchFlexTemplateResponse + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function launchFlexTemplate(LaunchFlexTemplateRequest $request, array $callOptions = []): LaunchFlexTemplateResponse + { + return $this->startApiCall('LaunchFlexTemplate', $request, $callOptions)->wait(); + } +} diff --git a/Dataflow/src/V1beta3/Client/BaseClient/JobsV1Beta3BaseClient.php b/Dataflow/src/V1beta3/Client/BaseClient/JobsV1Beta3BaseClient.php new file mode 100644 index 000000000000..0055e0cff209 --- /dev/null +++ b/Dataflow/src/V1beta3/Client/BaseClient/JobsV1Beta3BaseClient.php @@ -0,0 +1,391 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/jobs_v1_beta3_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/jobs_v1_beta3_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/jobs_v1_beta3_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/jobs_v1_beta3_rest_client_config.php', + ], + ], + ]; + } + + /** + * Constructor. + * + * @param array $options { + * Optional. Options for configuring the service API wrapper. + * + * @type string $apiEndpoint + * The address of the API remote host. May optionally include the port, formatted + * as ":". Default 'dataflow.googleapis.com:443'. + * @type string|array|FetchAuthTokenInterface|CredentialsWrapper $credentials + * The credentials to be used by the client to authorize API calls. This option + * accepts either a path to a credentials file, or a decoded credentials file as a + * PHP array. + * *Advanced usage*: In addition, this option can also accept a pre-constructed + * {@see \Google\Auth\FetchAuthTokenInterface} object or + * {@see \Google\ApiCore\CredentialsWrapper} object. Note that when one of these + * objects are provided, any settings in $credentialsConfig will be ignored. + * @type array $credentialsConfig + * Options used to configure credentials, including auth token caching, for the + * client. For a full list of supporting configuration options, see + * {@see \Google\ApiCore\CredentialsWrapper::build()} . + * @type bool $disableRetries + * Determines whether or not retries defined by the client configuration should be + * disabled. Defaults to `false`. + * @type string|array $clientConfig + * Client method configuration, including retry settings. This option can be either + * a path to a JSON file, or a PHP array containing the decoded JSON data. By + * default this settings points to the default client config file, which is + * provided in the resources folder. + * @type string|TransportInterface $transport + * The transport used for executing network requests. May be either the string + * `rest` or `grpc`. Defaults to `grpc` if gRPC support is detected on the system. + * *Advanced usage*: Additionally, it is possible to pass in an already + * instantiated {@see \Google\ApiCore\Transport\TransportInterface} object. Note + * that when this object is provided, any settings in $transportConfig, and any + * $apiEndpoint setting, will be ignored. + * @type array $transportConfig + * Configuration options that will be used to construct the transport. Options for + * each supported transport type should be passed in a key for that transport. For + * example: + * $transportConfig = [ + * 'grpc' => [...], + * 'rest' => [...], + * ]; + * See the {@see \Google\ApiCore\Transport\GrpcTransport::build()} and + * {@see \Google\ApiCore\Transport\RestTransport::build()} methods for the + * supported options. + * @type callable $clientCertSource + * A callable which returns the client cert as a string. This can be used to + * provide a certificate and private key to the transport layer for mTLS. + * } + * + * @throws ValidationException + * + * @experimental + */ + public function __construct(array $options = []) + { + $clientOptions = $this->buildClientOptions($options); + $this->setClientOptions($clientOptions); + } + + /** Handles execution of the async variants for each documented method. */ + public function __call($method, $args) + { + if (substr($method, -5) !== 'Async') { + trigger_error('Call to undefined method ' . __CLASS__ . "::$method()", E_USER_ERROR); + } + + array_unshift($args, substr($method, 0, -5)); + return call_user_func_array([$this, 'startAsyncCall'], $args); + } + + /** + * List the jobs of a project across all regions. + * + * The async variant is {@see self::aggregatedListJobsAsync()} . + * + * @param ListJobsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function aggregatedListJobs(ListJobsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('AggregatedListJobs', $request, $callOptions); + } + + /** + * Check for existence of active jobs in the given project across all regions. + * + * The async variant is {@see self::checkActiveJobsAsync()} . + * + * @param CheckActiveJobsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return CheckActiveJobsResponse + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function checkActiveJobs(CheckActiveJobsRequest $request, array $callOptions = []): CheckActiveJobsResponse + { + return $this->startApiCall('CheckActiveJobs', $request, $callOptions)->wait(); + } + + /** + * Creates a Cloud Dataflow job. + * + * To create a job, we recommend using `projects.locations.jobs.create` with a + * [regional endpoint] + * (https://cloud.google.com/dataflow/docs/concepts/regional-endpoints). Using + * `projects.jobs.create` is not recommended, as your job will always start + * in `us-central1`. + * + * The async variant is {@see self::createJobAsync()} . + * + * @param CreateJobRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Job + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function createJob(CreateJobRequest $request, array $callOptions = []): Job + { + return $this->startApiCall('CreateJob', $request, $callOptions)->wait(); + } + + /** + * Gets the state of the specified Cloud Dataflow job. + * + * To get the state of a job, we recommend using `projects.locations.jobs.get` + * with a [regional endpoint] + * (https://cloud.google.com/dataflow/docs/concepts/regional-endpoints). Using + * `projects.jobs.get` is not recommended, as you can only get the state of + * jobs that are running in `us-central1`. + * + * The async variant is {@see self::getJobAsync()} . + * + * @param GetJobRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Job + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function getJob(GetJobRequest $request, array $callOptions = []): Job + { + return $this->startApiCall('GetJob', $request, $callOptions)->wait(); + } + + /** + * List the jobs of a project. + * + * To list the jobs of a project in a region, we recommend using + * `projects.locations.jobs.list` with a [regional endpoint] + * (https://cloud.google.com/dataflow/docs/concepts/regional-endpoints). To + * list the all jobs across all regions, use `projects.jobs.aggregated`. Using + * `projects.jobs.list` is not recommended, as you can only get the list of + * jobs that are running in `us-central1`. + * + * The async variant is {@see self::listJobsAsync()} . + * + * @param ListJobsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function listJobs(ListJobsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListJobs', $request, $callOptions); + } + + /** + * Snapshot the state of a streaming job. + * + * The async variant is {@see self::snapshotJobAsync()} . + * + * @param SnapshotJobRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Snapshot + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function snapshotJob(SnapshotJobRequest $request, array $callOptions = []): Snapshot + { + return $this->startApiCall('SnapshotJob', $request, $callOptions)->wait(); + } + + /** + * Updates the state of an existing Cloud Dataflow job. + * + * To update the state of an existing job, we recommend using + * `projects.locations.jobs.update` with a [regional endpoint] + * (https://cloud.google.com/dataflow/docs/concepts/regional-endpoints). Using + * `projects.jobs.update` is not recommended, as you can only update the state + * of jobs that are running in `us-central1`. + * + * The async variant is {@see self::updateJobAsync()} . + * + * @param UpdateJobRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Job + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function updateJob(UpdateJobRequest $request, array $callOptions = []): Job + { + return $this->startApiCall('UpdateJob', $request, $callOptions)->wait(); + } +} diff --git a/Dataflow/src/V1beta3/Client/BaseClient/MessagesV1Beta3BaseClient.php b/Dataflow/src/V1beta3/Client/BaseClient/MessagesV1Beta3BaseClient.php new file mode 100644 index 000000000000..6696a270e71b --- /dev/null +++ b/Dataflow/src/V1beta3/Client/BaseClient/MessagesV1Beta3BaseClient.php @@ -0,0 +1,202 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/messages_v1_beta3_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/messages_v1_beta3_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/messages_v1_beta3_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/messages_v1_beta3_rest_client_config.php', + ], + ], + ]; + } + + /** + * Constructor. + * + * @param array $options { + * Optional. Options for configuring the service API wrapper. + * + * @type string $apiEndpoint + * The address of the API remote host. May optionally include the port, formatted + * as ":". Default 'dataflow.googleapis.com:443'. + * @type string|array|FetchAuthTokenInterface|CredentialsWrapper $credentials + * The credentials to be used by the client to authorize API calls. This option + * accepts either a path to a credentials file, or a decoded credentials file as a + * PHP array. + * *Advanced usage*: In addition, this option can also accept a pre-constructed + * {@see \Google\Auth\FetchAuthTokenInterface} object or + * {@see \Google\ApiCore\CredentialsWrapper} object. Note that when one of these + * objects are provided, any settings in $credentialsConfig will be ignored. + * @type array $credentialsConfig + * Options used to configure credentials, including auth token caching, for the + * client. For a full list of supporting configuration options, see + * {@see \Google\ApiCore\CredentialsWrapper::build()} . + * @type bool $disableRetries + * Determines whether or not retries defined by the client configuration should be + * disabled. Defaults to `false`. + * @type string|array $clientConfig + * Client method configuration, including retry settings. This option can be either + * a path to a JSON file, or a PHP array containing the decoded JSON data. By + * default this settings points to the default client config file, which is + * provided in the resources folder. + * @type string|TransportInterface $transport + * The transport used for executing network requests. May be either the string + * `rest` or `grpc`. Defaults to `grpc` if gRPC support is detected on the system. + * *Advanced usage*: Additionally, it is possible to pass in an already + * instantiated {@see \Google\ApiCore\Transport\TransportInterface} object. Note + * that when this object is provided, any settings in $transportConfig, and any + * $apiEndpoint setting, will be ignored. + * @type array $transportConfig + * Configuration options that will be used to construct the transport. Options for + * each supported transport type should be passed in a key for that transport. For + * example: + * $transportConfig = [ + * 'grpc' => [...], + * 'rest' => [...], + * ]; + * See the {@see \Google\ApiCore\Transport\GrpcTransport::build()} and + * {@see \Google\ApiCore\Transport\RestTransport::build()} methods for the + * supported options. + * @type callable $clientCertSource + * A callable which returns the client cert as a string. This can be used to + * provide a certificate and private key to the transport layer for mTLS. + * } + * + * @throws ValidationException + * + * @experimental + */ + public function __construct(array $options = []) + { + $clientOptions = $this->buildClientOptions($options); + $this->setClientOptions($clientOptions); + } + + /** Handles execution of the async variants for each documented method. */ + public function __call($method, $args) + { + if (substr($method, -5) !== 'Async') { + trigger_error('Call to undefined method ' . __CLASS__ . "::$method()", E_USER_ERROR); + } + + array_unshift($args, substr($method, 0, -5)); + return call_user_func_array([$this, 'startAsyncCall'], $args); + } + + /** + * Request the job status. + * + * To request the status of a job, we recommend using + * `projects.locations.jobs.messages.list` with a [regional endpoint] + * (https://cloud.google.com/dataflow/docs/concepts/regional-endpoints). Using + * `projects.jobs.messages.list` is not recommended, as you can only request + * the status of jobs that are running in `us-central1`. + * + * The async variant is {@see self::listJobMessagesAsync()} . + * + * @param ListJobMessagesRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function listJobMessages(ListJobMessagesRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListJobMessages', $request, $callOptions); + } +} diff --git a/Dataflow/src/V1beta3/Client/BaseClient/MetricsV1Beta3BaseClient.php b/Dataflow/src/V1beta3/Client/BaseClient/MetricsV1Beta3BaseClient.php new file mode 100644 index 000000000000..1ec5c38db0df --- /dev/null +++ b/Dataflow/src/V1beta3/Client/BaseClient/MetricsV1Beta3BaseClient.php @@ -0,0 +1,264 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/metrics_v1_beta3_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/metrics_v1_beta3_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/metrics_v1_beta3_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/metrics_v1_beta3_rest_client_config.php', + ], + ], + ]; + } + + /** + * Constructor. + * + * @param array $options { + * Optional. Options for configuring the service API wrapper. + * + * @type string $apiEndpoint + * The address of the API remote host. May optionally include the port, formatted + * as ":". Default 'dataflow.googleapis.com:443'. + * @type string|array|FetchAuthTokenInterface|CredentialsWrapper $credentials + * The credentials to be used by the client to authorize API calls. This option + * accepts either a path to a credentials file, or a decoded credentials file as a + * PHP array. + * *Advanced usage*: In addition, this option can also accept a pre-constructed + * {@see \Google\Auth\FetchAuthTokenInterface} object or + * {@see \Google\ApiCore\CredentialsWrapper} object. Note that when one of these + * objects are provided, any settings in $credentialsConfig will be ignored. + * @type array $credentialsConfig + * Options used to configure credentials, including auth token caching, for the + * client. For a full list of supporting configuration options, see + * {@see \Google\ApiCore\CredentialsWrapper::build()} . + * @type bool $disableRetries + * Determines whether or not retries defined by the client configuration should be + * disabled. Defaults to `false`. + * @type string|array $clientConfig + * Client method configuration, including retry settings. This option can be either + * a path to a JSON file, or a PHP array containing the decoded JSON data. By + * default this settings points to the default client config file, which is + * provided in the resources folder. + * @type string|TransportInterface $transport + * The transport used for executing network requests. May be either the string + * `rest` or `grpc`. Defaults to `grpc` if gRPC support is detected on the system. + * *Advanced usage*: Additionally, it is possible to pass in an already + * instantiated {@see \Google\ApiCore\Transport\TransportInterface} object. Note + * that when this object is provided, any settings in $transportConfig, and any + * $apiEndpoint setting, will be ignored. + * @type array $transportConfig + * Configuration options that will be used to construct the transport. Options for + * each supported transport type should be passed in a key for that transport. For + * example: + * $transportConfig = [ + * 'grpc' => [...], + * 'rest' => [...], + * ]; + * See the {@see \Google\ApiCore\Transport\GrpcTransport::build()} and + * {@see \Google\ApiCore\Transport\RestTransport::build()} methods for the + * supported options. + * @type callable $clientCertSource + * A callable which returns the client cert as a string. This can be used to + * provide a certificate and private key to the transport layer for mTLS. + * } + * + * @throws ValidationException + * + * @experimental + */ + public function __construct(array $options = []) + { + $clientOptions = $this->buildClientOptions($options); + $this->setClientOptions($clientOptions); + } + + /** Handles execution of the async variants for each documented method. */ + public function __call($method, $args) + { + if (substr($method, -5) !== 'Async') { + trigger_error('Call to undefined method ' . __CLASS__ . "::$method()", E_USER_ERROR); + } + + array_unshift($args, substr($method, 0, -5)); + return call_user_func_array([$this, 'startAsyncCall'], $args); + } + + /** + * Request detailed information about the execution status of the job. + * + * EXPERIMENTAL. This API is subject to change or removal without notice. + * + * The async variant is {@see self::getJobExecutionDetailsAsync()} . + * + * @param GetJobExecutionDetailsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function getJobExecutionDetails(GetJobExecutionDetailsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('GetJobExecutionDetails', $request, $callOptions); + } + + /** + * Request the job status. + * + * To request the status of a job, we recommend using + * `projects.locations.jobs.getMetrics` with a [regional endpoint] + * (https://cloud.google.com/dataflow/docs/concepts/regional-endpoints). Using + * `projects.jobs.getMetrics` is not recommended, as you can only request the + * status of jobs that are running in `us-central1`. + * + * The async variant is {@see self::getJobMetricsAsync()} . + * + * @param GetJobMetricsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return JobMetrics + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function getJobMetrics(GetJobMetricsRequest $request, array $callOptions = []): JobMetrics + { + return $this->startApiCall('GetJobMetrics', $request, $callOptions)->wait(); + } + + /** + * Request detailed information about the execution status of a stage of the + * job. + * + * EXPERIMENTAL. This API is subject to change or removal without notice. + * + * The async variant is {@see self::getStageExecutionDetailsAsync()} . + * + * @param GetStageExecutionDetailsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function getStageExecutionDetails(GetStageExecutionDetailsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('GetStageExecutionDetails', $request, $callOptions); + } +} diff --git a/Dataflow/src/V1beta3/Client/BaseClient/SnapshotsV1Beta3BaseClient.php b/Dataflow/src/V1beta3/Client/BaseClient/SnapshotsV1Beta3BaseClient.php new file mode 100644 index 000000000000..4ba72b8c5620 --- /dev/null +++ b/Dataflow/src/V1beta3/Client/BaseClient/SnapshotsV1Beta3BaseClient.php @@ -0,0 +1,253 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/snapshots_v1_beta3_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/snapshots_v1_beta3_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/snapshots_v1_beta3_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/snapshots_v1_beta3_rest_client_config.php', + ], + ], + ]; + } + + /** + * Constructor. + * + * @param array $options { + * Optional. Options for configuring the service API wrapper. + * + * @type string $apiEndpoint + * The address of the API remote host. May optionally include the port, formatted + * as ":". Default 'dataflow.googleapis.com:443'. + * @type string|array|FetchAuthTokenInterface|CredentialsWrapper $credentials + * The credentials to be used by the client to authorize API calls. This option + * accepts either a path to a credentials file, or a decoded credentials file as a + * PHP array. + * *Advanced usage*: In addition, this option can also accept a pre-constructed + * {@see \Google\Auth\FetchAuthTokenInterface} object or + * {@see \Google\ApiCore\CredentialsWrapper} object. Note that when one of these + * objects are provided, any settings in $credentialsConfig will be ignored. + * @type array $credentialsConfig + * Options used to configure credentials, including auth token caching, for the + * client. For a full list of supporting configuration options, see + * {@see \Google\ApiCore\CredentialsWrapper::build()} . + * @type bool $disableRetries + * Determines whether or not retries defined by the client configuration should be + * disabled. Defaults to `false`. + * @type string|array $clientConfig + * Client method configuration, including retry settings. This option can be either + * a path to a JSON file, or a PHP array containing the decoded JSON data. By + * default this settings points to the default client config file, which is + * provided in the resources folder. + * @type string|TransportInterface $transport + * The transport used for executing network requests. May be either the string + * `rest` or `grpc`. Defaults to `grpc` if gRPC support is detected on the system. + * *Advanced usage*: Additionally, it is possible to pass in an already + * instantiated {@see \Google\ApiCore\Transport\TransportInterface} object. Note + * that when this object is provided, any settings in $transportConfig, and any + * $apiEndpoint setting, will be ignored. + * @type array $transportConfig + * Configuration options that will be used to construct the transport. Options for + * each supported transport type should be passed in a key for that transport. For + * example: + * $transportConfig = [ + * 'grpc' => [...], + * 'rest' => [...], + * ]; + * See the {@see \Google\ApiCore\Transport\GrpcTransport::build()} and + * {@see \Google\ApiCore\Transport\RestTransport::build()} methods for the + * supported options. + * @type callable $clientCertSource + * A callable which returns the client cert as a string. This can be used to + * provide a certificate and private key to the transport layer for mTLS. + * } + * + * @throws ValidationException + * + * @experimental + */ + public function __construct(array $options = []) + { + $clientOptions = $this->buildClientOptions($options); + $this->setClientOptions($clientOptions); + } + + /** Handles execution of the async variants for each documented method. */ + public function __call($method, $args) + { + if (substr($method, -5) !== 'Async') { + trigger_error('Call to undefined method ' . __CLASS__ . "::$method()", E_USER_ERROR); + } + + array_unshift($args, substr($method, 0, -5)); + return call_user_func_array([$this, 'startAsyncCall'], $args); + } + + /** + * Deletes a snapshot. + * + * The async variant is {@see self::deleteSnapshotAsync()} . + * + * @param DeleteSnapshotRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return DeleteSnapshotResponse + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function deleteSnapshot(DeleteSnapshotRequest $request, array $callOptions = []): DeleteSnapshotResponse + { + return $this->startApiCall('DeleteSnapshot', $request, $callOptions)->wait(); + } + + /** + * Gets information about a snapshot. + * + * The async variant is {@see self::getSnapshotAsync()} . + * + * @param GetSnapshotRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Snapshot + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function getSnapshot(GetSnapshotRequest $request, array $callOptions = []): Snapshot + { + return $this->startApiCall('GetSnapshot', $request, $callOptions)->wait(); + } + + /** + * Lists snapshots. + * + * The async variant is {@see self::listSnapshotsAsync()} . + * + * @param ListSnapshotsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return ListSnapshotsResponse + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function listSnapshots(ListSnapshotsRequest $request, array $callOptions = []): ListSnapshotsResponse + { + return $this->startApiCall('ListSnapshots', $request, $callOptions)->wait(); + } +} diff --git a/Dataflow/src/V1beta3/Client/BaseClient/TemplatesServiceBaseClient.php b/Dataflow/src/V1beta3/Client/BaseClient/TemplatesServiceBaseClient.php new file mode 100644 index 000000000000..71fa29ecb905 --- /dev/null +++ b/Dataflow/src/V1beta3/Client/BaseClient/TemplatesServiceBaseClient.php @@ -0,0 +1,253 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/templates_service_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/templates_service_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/templates_service_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/templates_service_rest_client_config.php', + ], + ], + ]; + } + + /** + * Constructor. + * + * @param array $options { + * Optional. Options for configuring the service API wrapper. + * + * @type string $apiEndpoint + * The address of the API remote host. May optionally include the port, formatted + * as ":". Default 'dataflow.googleapis.com:443'. + * @type string|array|FetchAuthTokenInterface|CredentialsWrapper $credentials + * The credentials to be used by the client to authorize API calls. This option + * accepts either a path to a credentials file, or a decoded credentials file as a + * PHP array. + * *Advanced usage*: In addition, this option can also accept a pre-constructed + * {@see \Google\Auth\FetchAuthTokenInterface} object or + * {@see \Google\ApiCore\CredentialsWrapper} object. Note that when one of these + * objects are provided, any settings in $credentialsConfig will be ignored. + * @type array $credentialsConfig + * Options used to configure credentials, including auth token caching, for the + * client. For a full list of supporting configuration options, see + * {@see \Google\ApiCore\CredentialsWrapper::build()} . + * @type bool $disableRetries + * Determines whether or not retries defined by the client configuration should be + * disabled. Defaults to `false`. + * @type string|array $clientConfig + * Client method configuration, including retry settings. This option can be either + * a path to a JSON file, or a PHP array containing the decoded JSON data. By + * default this settings points to the default client config file, which is + * provided in the resources folder. + * @type string|TransportInterface $transport + * The transport used for executing network requests. May be either the string + * `rest` or `grpc`. Defaults to `grpc` if gRPC support is detected on the system. + * *Advanced usage*: Additionally, it is possible to pass in an already + * instantiated {@see \Google\ApiCore\Transport\TransportInterface} object. Note + * that when this object is provided, any settings in $transportConfig, and any + * $apiEndpoint setting, will be ignored. + * @type array $transportConfig + * Configuration options that will be used to construct the transport. Options for + * each supported transport type should be passed in a key for that transport. For + * example: + * $transportConfig = [ + * 'grpc' => [...], + * 'rest' => [...], + * ]; + * See the {@see \Google\ApiCore\Transport\GrpcTransport::build()} and + * {@see \Google\ApiCore\Transport\RestTransport::build()} methods for the + * supported options. + * @type callable $clientCertSource + * A callable which returns the client cert as a string. This can be used to + * provide a certificate and private key to the transport layer for mTLS. + * } + * + * @throws ValidationException + * + * @experimental + */ + public function __construct(array $options = []) + { + $clientOptions = $this->buildClientOptions($options); + $this->setClientOptions($clientOptions); + } + + /** Handles execution of the async variants for each documented method. */ + public function __call($method, $args) + { + if (substr($method, -5) !== 'Async') { + trigger_error('Call to undefined method ' . __CLASS__ . "::$method()", E_USER_ERROR); + } + + array_unshift($args, substr($method, 0, -5)); + return call_user_func_array([$this, 'startAsyncCall'], $args); + } + + /** + * Creates a Cloud Dataflow job from a template. + * + * The async variant is {@see self::createJobFromTemplateAsync()} . + * + * @param CreateJobFromTemplateRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Job + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function createJobFromTemplate(CreateJobFromTemplateRequest $request, array $callOptions = []): Job + { + return $this->startApiCall('CreateJobFromTemplate', $request, $callOptions)->wait(); + } + + /** + * Get the template associated with a template. + * + * The async variant is {@see self::getTemplateAsync()} . + * + * @param GetTemplateRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return GetTemplateResponse + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function getTemplate(GetTemplateRequest $request, array $callOptions = []): GetTemplateResponse + { + return $this->startApiCall('GetTemplate', $request, $callOptions)->wait(); + } + + /** + * Launch a template. + * + * The async variant is {@see self::launchTemplateAsync()} . + * + * @param LaunchTemplateRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return LaunchTemplateResponse + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function launchTemplate(LaunchTemplateRequest $request, array $callOptions = []): LaunchTemplateResponse + { + return $this->startApiCall('LaunchTemplate', $request, $callOptions)->wait(); + } +} diff --git a/Dataflow/src/V1beta3/Client/FlexTemplatesServiceClient.php b/Dataflow/src/V1beta3/Client/FlexTemplatesServiceClient.php new file mode 100644 index 000000000000..f4d935444254 --- /dev/null +++ b/Dataflow/src/V1beta3/Client/FlexTemplatesServiceClient.php @@ -0,0 +1,42 @@ + [ - 'google.dataflow.v1beta3.FlexTemplatesService' => [], + 'google.dataflow.v1beta3.FlexTemplatesService' => [ + 'LaunchFlexTemplate' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Dataflow\V1beta3\LaunchFlexTemplateResponse', + 'headerParams' => [ + [ + 'keyName' => 'project_id', + 'fieldAccessors' => [ + 'getProjectId', + ], + ], + [ + 'keyName' => 'location', + 'fieldAccessors' => [ + 'getLocation', + ], + ], + ], + ], + ], ], ]; diff --git a/Dataflow/src/V1beta3/resources/jobs_v1_beta3_descriptor_config.php b/Dataflow/src/V1beta3/resources/jobs_v1_beta3_descriptor_config.php index 9a769cbe5af9..72fac5975de0 100644 --- a/Dataflow/src/V1beta3/resources/jobs_v1_beta3_descriptor_config.php +++ b/Dataflow/src/V1beta3/resources/jobs_v1_beta3_descriptor_config.php @@ -12,6 +12,62 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getJobs', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\Dataflow\V1beta3\ListJobsResponse', + 'headerParams' => [ + [ + 'keyName' => 'project_id', + 'fieldAccessors' => [ + 'getProjectId', + ], + ], + ], + ], + 'CheckActiveJobs' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Dataflow\V1beta3\CheckActiveJobsResponse', + ], + 'CreateJob' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Dataflow\V1beta3\Job', + 'headerParams' => [ + [ + 'keyName' => 'project_id', + 'fieldAccessors' => [ + 'getProjectId', + ], + ], + [ + 'keyName' => 'location', + 'fieldAccessors' => [ + 'getLocation', + ], + ], + ], + ], + 'GetJob' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Dataflow\V1beta3\Job', + 'headerParams' => [ + [ + 'keyName' => 'project_id', + 'fieldAccessors' => [ + 'getProjectId', + ], + ], + [ + 'keyName' => 'job_id', + 'fieldAccessors' => [ + 'getJobId', + ], + ], + [ + 'keyName' => 'location', + 'fieldAccessors' => [ + 'getLocation', + ], + ], + ], ], 'ListJobs' => [ 'pageStreaming' => [ @@ -22,6 +78,70 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getJobs', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\Dataflow\V1beta3\ListJobsResponse', + 'headerParams' => [ + [ + 'keyName' => 'project_id', + 'fieldAccessors' => [ + 'getProjectId', + ], + ], + [ + 'keyName' => 'location', + 'fieldAccessors' => [ + 'getLocation', + ], + ], + ], + ], + 'SnapshotJob' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Dataflow\V1beta3\Snapshot', + 'headerParams' => [ + [ + 'keyName' => 'project_id', + 'fieldAccessors' => [ + 'getProjectId', + ], + ], + [ + 'keyName' => 'job_id', + 'fieldAccessors' => [ + 'getJobId', + ], + ], + [ + 'keyName' => 'location', + 'fieldAccessors' => [ + 'getLocation', + ], + ], + ], + ], + 'UpdateJob' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Dataflow\V1beta3\Job', + 'headerParams' => [ + [ + 'keyName' => 'project_id', + 'fieldAccessors' => [ + 'getProjectId', + ], + ], + [ + 'keyName' => 'job_id', + 'fieldAccessors' => [ + 'getJobId', + ], + ], + [ + 'keyName' => 'location', + 'fieldAccessors' => [ + 'getLocation', + ], + ], + ], ], ], ], diff --git a/Dataflow/src/V1beta3/resources/messages_v1_beta3_descriptor_config.php b/Dataflow/src/V1beta3/resources/messages_v1_beta3_descriptor_config.php index 83655ac1e9ac..92e76f70edec 100644 --- a/Dataflow/src/V1beta3/resources/messages_v1_beta3_descriptor_config.php +++ b/Dataflow/src/V1beta3/resources/messages_v1_beta3_descriptor_config.php @@ -12,6 +12,28 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getJobMessages', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\Dataflow\V1beta3\ListJobMessagesResponse', + 'headerParams' => [ + [ + 'keyName' => 'project_id', + 'fieldAccessors' => [ + 'getProjectId', + ], + ], + [ + 'keyName' => 'job_id', + 'fieldAccessors' => [ + 'getJobId', + ], + ], + [ + 'keyName' => 'location', + 'fieldAccessors' => [ + 'getLocation', + ], + ], + ], ], ], ], diff --git a/Dataflow/src/V1beta3/resources/metrics_v1_beta3_descriptor_config.php b/Dataflow/src/V1beta3/resources/metrics_v1_beta3_descriptor_config.php index c125d09fbee0..298c38d58a43 100644 --- a/Dataflow/src/V1beta3/resources/metrics_v1_beta3_descriptor_config.php +++ b/Dataflow/src/V1beta3/resources/metrics_v1_beta3_descriptor_config.php @@ -12,6 +12,52 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getStages', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\Dataflow\V1beta3\JobExecutionDetails', + 'headerParams' => [ + [ + 'keyName' => 'project_id', + 'fieldAccessors' => [ + 'getProjectId', + ], + ], + [ + 'keyName' => 'location', + 'fieldAccessors' => [ + 'getLocation', + ], + ], + [ + 'keyName' => 'job_id', + 'fieldAccessors' => [ + 'getJobId', + ], + ], + ], + ], + 'GetJobMetrics' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Dataflow\V1beta3\JobMetrics', + 'headerParams' => [ + [ + 'keyName' => 'project_id', + 'fieldAccessors' => [ + 'getProjectId', + ], + ], + [ + 'keyName' => 'job_id', + 'fieldAccessors' => [ + 'getJobId', + ], + ], + [ + 'keyName' => 'location', + 'fieldAccessors' => [ + 'getLocation', + ], + ], + ], ], 'GetStageExecutionDetails' => [ 'pageStreaming' => [ @@ -22,6 +68,34 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getWorkers', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\Dataflow\V1beta3\StageExecutionDetails', + 'headerParams' => [ + [ + 'keyName' => 'project_id', + 'fieldAccessors' => [ + 'getProjectId', + ], + ], + [ + 'keyName' => 'location', + 'fieldAccessors' => [ + 'getLocation', + ], + ], + [ + 'keyName' => 'job_id', + 'fieldAccessors' => [ + 'getJobId', + ], + ], + [ + 'keyName' => 'stage_id', + 'fieldAccessors' => [ + 'getStageId', + ], + ], + ], ], ], ], diff --git a/Dataflow/src/V1beta3/resources/snapshots_v1_beta3_descriptor_config.php b/Dataflow/src/V1beta3/resources/snapshots_v1_beta3_descriptor_config.php index 2f6341e70739..997e29031e3e 100644 --- a/Dataflow/src/V1beta3/resources/snapshots_v1_beta3_descriptor_config.php +++ b/Dataflow/src/V1beta3/resources/snapshots_v1_beta3_descriptor_config.php @@ -2,6 +2,79 @@ return [ 'interfaces' => [ - 'google.dataflow.v1beta3.SnapshotsV1Beta3' => [], + 'google.dataflow.v1beta3.SnapshotsV1Beta3' => [ + 'DeleteSnapshot' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Dataflow\V1beta3\DeleteSnapshotResponse', + 'headerParams' => [ + [ + 'keyName' => 'project_id', + 'fieldAccessors' => [ + 'getProjectId', + ], + ], + [ + 'keyName' => 'location', + 'fieldAccessors' => [ + 'getLocation', + ], + ], + [ + 'keyName' => 'snapshot_id', + 'fieldAccessors' => [ + 'getSnapshotId', + ], + ], + ], + ], + 'GetSnapshot' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Dataflow\V1beta3\Snapshot', + 'headerParams' => [ + [ + 'keyName' => 'project_id', + 'fieldAccessors' => [ + 'getProjectId', + ], + ], + [ + 'keyName' => 'snapshot_id', + 'fieldAccessors' => [ + 'getSnapshotId', + ], + ], + [ + 'keyName' => 'location', + 'fieldAccessors' => [ + 'getLocation', + ], + ], + ], + ], + 'ListSnapshots' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Dataflow\V1beta3\ListSnapshotsResponse', + 'headerParams' => [ + [ + 'keyName' => 'project_id', + 'fieldAccessors' => [ + 'getProjectId', + ], + ], + [ + 'keyName' => 'location', + 'fieldAccessors' => [ + 'getLocation', + ], + ], + [ + 'keyName' => 'job_id', + 'fieldAccessors' => [ + 'getJobId', + ], + ], + ], + ], + ], ], ]; diff --git a/Dataflow/src/V1beta3/resources/templates_service_descriptor_config.php b/Dataflow/src/V1beta3/resources/templates_service_descriptor_config.php index 730778f71818..f826b2612275 100644 --- a/Dataflow/src/V1beta3/resources/templates_service_descriptor_config.php +++ b/Dataflow/src/V1beta3/resources/templates_service_descriptor_config.php @@ -2,6 +2,61 @@ return [ 'interfaces' => [ - 'google.dataflow.v1beta3.TemplatesService' => [], + 'google.dataflow.v1beta3.TemplatesService' => [ + 'CreateJobFromTemplate' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Dataflow\V1beta3\Job', + 'headerParams' => [ + [ + 'keyName' => 'project_id', + 'fieldAccessors' => [ + 'getProjectId', + ], + ], + [ + 'keyName' => 'location', + 'fieldAccessors' => [ + 'getLocation', + ], + ], + ], + ], + 'GetTemplate' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Dataflow\V1beta3\GetTemplateResponse', + 'headerParams' => [ + [ + 'keyName' => 'project_id', + 'fieldAccessors' => [ + 'getProjectId', + ], + ], + [ + 'keyName' => 'location', + 'fieldAccessors' => [ + 'getLocation', + ], + ], + ], + ], + 'LaunchTemplate' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Dataflow\V1beta3\LaunchTemplateResponse', + 'headerParams' => [ + [ + 'keyName' => 'project_id', + 'fieldAccessors' => [ + 'getProjectId', + ], + ], + [ + 'keyName' => 'location', + 'fieldAccessors' => [ + 'getLocation', + ], + ], + ], + ], + ], ], ]; diff --git a/Dataflow/tests/Unit/V1beta3/Client/FlexTemplatesServiceClientTest.php b/Dataflow/tests/Unit/V1beta3/Client/FlexTemplatesServiceClientTest.php new file mode 100644 index 000000000000..8d54cbd10790 --- /dev/null +++ b/Dataflow/tests/Unit/V1beta3/Client/FlexTemplatesServiceClientTest.php @@ -0,0 +1,138 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return FlexTemplatesServiceClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new FlexTemplatesServiceClient($options); + } + + /** @test */ + public function launchFlexTemplateTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new LaunchFlexTemplateResponse(); + $transport->addResponse($expectedResponse); + $request = new LaunchFlexTemplateRequest(); + $response = $gapicClient->launchFlexTemplate($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.dataflow.v1beta3.FlexTemplatesService/LaunchFlexTemplate', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function launchFlexTemplateExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + $request = new LaunchFlexTemplateRequest(); + try { + $gapicClient->launchFlexTemplate($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function launchFlexTemplateAsyncTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new LaunchFlexTemplateResponse(); + $transport->addResponse($expectedResponse); + $request = new LaunchFlexTemplateRequest(); + $response = $gapicClient->launchFlexTemplateAsync($request)->wait(); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.dataflow.v1beta3.FlexTemplatesService/LaunchFlexTemplate', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } +} diff --git a/Dataflow/tests/Unit/V1beta3/Client/JobsV1Beta3ClientTest.php b/Dataflow/tests/Unit/V1beta3/Client/JobsV1Beta3ClientTest.php new file mode 100644 index 000000000000..21b377883026 --- /dev/null +++ b/Dataflow/tests/Unit/V1beta3/Client/JobsV1Beta3ClientTest.php @@ -0,0 +1,574 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return JobsV1Beta3Client */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new JobsV1Beta3Client($options); + } + + /** @test */ + public function aggregatedListJobsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $jobsElement = new Job(); + $jobs = [ + $jobsElement, + ]; + $expectedResponse = new ListJobsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setJobs($jobs); + $transport->addResponse($expectedResponse); + $request = new ListJobsRequest(); + $response = $gapicClient->aggregatedListJobs($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getJobs()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.dataflow.v1beta3.JobsV1Beta3/AggregatedListJobs', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function aggregatedListJobsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + $request = new ListJobsRequest(); + try { + $gapicClient->aggregatedListJobs($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function checkActiveJobsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $activeJobsExist = false; + $expectedResponse = new CheckActiveJobsResponse(); + $expectedResponse->setActiveJobsExist($activeJobsExist); + $transport->addResponse($expectedResponse); + $request = new CheckActiveJobsRequest(); + $response = $gapicClient->checkActiveJobs($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.dataflow.v1beta3.JobsV1Beta3/CheckActiveJobs', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function checkActiveJobsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + $request = new CheckActiveJobsRequest(); + try { + $gapicClient->checkActiveJobs($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createJobTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $id = 'id3355'; + $projectId2 = 'projectId2939242356'; + $name = 'name3373707'; + $stepsLocation = 'stepsLocation-354969139'; + $replaceJobId2 = 'replaceJobId2-609521029'; + $clientRequestId = 'clientRequestId-1902516801'; + $replacedByJobId = 'replacedByJobId-671370122'; + $location2 = 'location21541837352'; + $createdFromSnapshotId = 'createdFromSnapshotId1520659672'; + $satisfiesPzs = false; + $expectedResponse = new Job(); + $expectedResponse->setId($id); + $expectedResponse->setProjectId($projectId2); + $expectedResponse->setName($name); + $expectedResponse->setStepsLocation($stepsLocation); + $expectedResponse->setReplaceJobId($replaceJobId2); + $expectedResponse->setClientRequestId($clientRequestId); + $expectedResponse->setReplacedByJobId($replacedByJobId); + $expectedResponse->setLocation($location2); + $expectedResponse->setCreatedFromSnapshotId($createdFromSnapshotId); + $expectedResponse->setSatisfiesPzs($satisfiesPzs); + $transport->addResponse($expectedResponse); + $request = new CreateJobRequest(); + $response = $gapicClient->createJob($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.dataflow.v1beta3.JobsV1Beta3/CreateJob', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createJobExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + $request = new CreateJobRequest(); + try { + $gapicClient->createJob($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getJobTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $id = 'id3355'; + $projectId2 = 'projectId2939242356'; + $name = 'name3373707'; + $stepsLocation = 'stepsLocation-354969139'; + $replaceJobId = 'replaceJobId459700424'; + $clientRequestId = 'clientRequestId-1902516801'; + $replacedByJobId = 'replacedByJobId-671370122'; + $location2 = 'location21541837352'; + $createdFromSnapshotId = 'createdFromSnapshotId1520659672'; + $satisfiesPzs = false; + $expectedResponse = new Job(); + $expectedResponse->setId($id); + $expectedResponse->setProjectId($projectId2); + $expectedResponse->setName($name); + $expectedResponse->setStepsLocation($stepsLocation); + $expectedResponse->setReplaceJobId($replaceJobId); + $expectedResponse->setClientRequestId($clientRequestId); + $expectedResponse->setReplacedByJobId($replacedByJobId); + $expectedResponse->setLocation($location2); + $expectedResponse->setCreatedFromSnapshotId($createdFromSnapshotId); + $expectedResponse->setSatisfiesPzs($satisfiesPzs); + $transport->addResponse($expectedResponse); + $request = new GetJobRequest(); + $response = $gapicClient->getJob($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.dataflow.v1beta3.JobsV1Beta3/GetJob', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getJobExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + $request = new GetJobRequest(); + try { + $gapicClient->getJob($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listJobsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $jobsElement = new Job(); + $jobs = [ + $jobsElement, + ]; + $expectedResponse = new ListJobsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setJobs($jobs); + $transport->addResponse($expectedResponse); + $request = new ListJobsRequest(); + $response = $gapicClient->listJobs($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getJobs()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.dataflow.v1beta3.JobsV1Beta3/ListJobs', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listJobsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + $request = new ListJobsRequest(); + try { + $gapicClient->listJobs($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function snapshotJobTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $id = 'id3355'; + $projectId2 = 'projectId2939242356'; + $sourceJobId = 'sourceJobId-16371327'; + $description2 = 'description2568623279'; + $diskSizeBytes = 275393905; + $region = 'region-934795532'; + $expectedResponse = new Snapshot(); + $expectedResponse->setId($id); + $expectedResponse->setProjectId($projectId2); + $expectedResponse->setSourceJobId($sourceJobId); + $expectedResponse->setDescription($description2); + $expectedResponse->setDiskSizeBytes($diskSizeBytes); + $expectedResponse->setRegion($region); + $transport->addResponse($expectedResponse); + $request = new SnapshotJobRequest(); + $response = $gapicClient->snapshotJob($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.dataflow.v1beta3.JobsV1Beta3/SnapshotJob', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function snapshotJobExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + $request = new SnapshotJobRequest(); + try { + $gapicClient->snapshotJob($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function updateJobTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $id = 'id3355'; + $projectId2 = 'projectId2939242356'; + $name = 'name3373707'; + $stepsLocation = 'stepsLocation-354969139'; + $replaceJobId = 'replaceJobId459700424'; + $clientRequestId = 'clientRequestId-1902516801'; + $replacedByJobId = 'replacedByJobId-671370122'; + $location2 = 'location21541837352'; + $createdFromSnapshotId = 'createdFromSnapshotId1520659672'; + $satisfiesPzs = false; + $expectedResponse = new Job(); + $expectedResponse->setId($id); + $expectedResponse->setProjectId($projectId2); + $expectedResponse->setName($name); + $expectedResponse->setStepsLocation($stepsLocation); + $expectedResponse->setReplaceJobId($replaceJobId); + $expectedResponse->setClientRequestId($clientRequestId); + $expectedResponse->setReplacedByJobId($replacedByJobId); + $expectedResponse->setLocation($location2); + $expectedResponse->setCreatedFromSnapshotId($createdFromSnapshotId); + $expectedResponse->setSatisfiesPzs($satisfiesPzs); + $transport->addResponse($expectedResponse); + $request = new UpdateJobRequest(); + $response = $gapicClient->updateJob($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.dataflow.v1beta3.JobsV1Beta3/UpdateJob', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function updateJobExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + $request = new UpdateJobRequest(); + try { + $gapicClient->updateJob($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function aggregatedListJobsAsyncTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $jobsElement = new Job(); + $jobs = [ + $jobsElement, + ]; + $expectedResponse = new ListJobsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setJobs($jobs); + $transport->addResponse($expectedResponse); + $request = new ListJobsRequest(); + $response = $gapicClient->aggregatedListJobsAsync($request)->wait(); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getJobs()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.dataflow.v1beta3.JobsV1Beta3/AggregatedListJobs', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } +} diff --git a/Dataflow/tests/Unit/V1beta3/Client/MessagesV1Beta3ClientTest.php b/Dataflow/tests/Unit/V1beta3/Client/MessagesV1Beta3ClientTest.php new file mode 100644 index 000000000000..a7cd94d3371b --- /dev/null +++ b/Dataflow/tests/Unit/V1beta3/Client/MessagesV1Beta3ClientTest.php @@ -0,0 +1,159 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return MessagesV1Beta3Client */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new MessagesV1Beta3Client($options); + } + + /** @test */ + public function listJobMessagesTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $jobMessagesElement = new JobMessage(); + $jobMessages = [ + $jobMessagesElement, + ]; + $expectedResponse = new ListJobMessagesResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setJobMessages($jobMessages); + $transport->addResponse($expectedResponse); + $request = new ListJobMessagesRequest(); + $response = $gapicClient->listJobMessages($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getJobMessages()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.dataflow.v1beta3.MessagesV1Beta3/ListJobMessages', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listJobMessagesExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + $request = new ListJobMessagesRequest(); + try { + $gapicClient->listJobMessages($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listJobMessagesAsyncTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $jobMessagesElement = new JobMessage(); + $jobMessages = [ + $jobMessagesElement, + ]; + $expectedResponse = new ListJobMessagesResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setJobMessages($jobMessages); + $transport->addResponse($expectedResponse); + $request = new ListJobMessagesRequest(); + $response = $gapicClient->listJobMessagesAsync($request)->wait(); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getJobMessages()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.dataflow.v1beta3.MessagesV1Beta3/ListJobMessages', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } +} diff --git a/Dataflow/tests/Unit/V1beta3/Client/MetricsV1Beta3ClientTest.php b/Dataflow/tests/Unit/V1beta3/Client/MetricsV1Beta3ClientTest.php new file mode 100644 index 000000000000..31d1d06e3572 --- /dev/null +++ b/Dataflow/tests/Unit/V1beta3/Client/MetricsV1Beta3ClientTest.php @@ -0,0 +1,282 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return MetricsV1Beta3Client */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new MetricsV1Beta3Client($options); + } + + /** @test */ + public function getJobExecutionDetailsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $stagesElement = new StageSummary(); + $stages = [ + $stagesElement, + ]; + $expectedResponse = new JobExecutionDetails(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setStages($stages); + $transport->addResponse($expectedResponse); + $request = new GetJobExecutionDetailsRequest(); + $response = $gapicClient->getJobExecutionDetails($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getStages()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.dataflow.v1beta3.MetricsV1Beta3/GetJobExecutionDetails', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getJobExecutionDetailsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + $request = new GetJobExecutionDetailsRequest(); + try { + $gapicClient->getJobExecutionDetails($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getJobMetricsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new JobMetrics(); + $transport->addResponse($expectedResponse); + $request = new GetJobMetricsRequest(); + $response = $gapicClient->getJobMetrics($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.dataflow.v1beta3.MetricsV1Beta3/GetJobMetrics', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getJobMetricsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + $request = new GetJobMetricsRequest(); + try { + $gapicClient->getJobMetrics($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getStageExecutionDetailsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $workersElement = new WorkerDetails(); + $workers = [ + $workersElement, + ]; + $expectedResponse = new StageExecutionDetails(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setWorkers($workers); + $transport->addResponse($expectedResponse); + $request = new GetStageExecutionDetailsRequest(); + $response = $gapicClient->getStageExecutionDetails($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getWorkers()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.dataflow.v1beta3.MetricsV1Beta3/GetStageExecutionDetails', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getStageExecutionDetailsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + $request = new GetStageExecutionDetailsRequest(); + try { + $gapicClient->getStageExecutionDetails($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getJobExecutionDetailsAsyncTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $stagesElement = new StageSummary(); + $stages = [ + $stagesElement, + ]; + $expectedResponse = new JobExecutionDetails(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setStages($stages); + $transport->addResponse($expectedResponse); + $request = new GetJobExecutionDetailsRequest(); + $response = $gapicClient->getJobExecutionDetailsAsync($request)->wait(); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getStages()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.dataflow.v1beta3.MetricsV1Beta3/GetJobExecutionDetails', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } +} diff --git a/Dataflow/tests/Unit/V1beta3/Client/SnapshotsV1Beta3ClientTest.php b/Dataflow/tests/Unit/V1beta3/Client/SnapshotsV1Beta3ClientTest.php new file mode 100644 index 000000000000..03b97b9da8bd --- /dev/null +++ b/Dataflow/tests/Unit/V1beta3/Client/SnapshotsV1Beta3ClientTest.php @@ -0,0 +1,262 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return SnapshotsV1Beta3Client */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new SnapshotsV1Beta3Client($options); + } + + /** @test */ + public function deleteSnapshotTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new DeleteSnapshotResponse(); + $transport->addResponse($expectedResponse); + $request = new DeleteSnapshotRequest(); + $response = $gapicClient->deleteSnapshot($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.dataflow.v1beta3.SnapshotsV1Beta3/DeleteSnapshot', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteSnapshotExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + $request = new DeleteSnapshotRequest(); + try { + $gapicClient->deleteSnapshot($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getSnapshotTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $id = 'id3355'; + $projectId2 = 'projectId2939242356'; + $sourceJobId = 'sourceJobId-16371327'; + $description = 'description-1724546052'; + $diskSizeBytes = 275393905; + $region = 'region-934795532'; + $expectedResponse = new Snapshot(); + $expectedResponse->setId($id); + $expectedResponse->setProjectId($projectId2); + $expectedResponse->setSourceJobId($sourceJobId); + $expectedResponse->setDescription($description); + $expectedResponse->setDiskSizeBytes($diskSizeBytes); + $expectedResponse->setRegion($region); + $transport->addResponse($expectedResponse); + $request = new GetSnapshotRequest(); + $response = $gapicClient->getSnapshot($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.dataflow.v1beta3.SnapshotsV1Beta3/GetSnapshot', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getSnapshotExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + $request = new GetSnapshotRequest(); + try { + $gapicClient->getSnapshot($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listSnapshotsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new ListSnapshotsResponse(); + $transport->addResponse($expectedResponse); + $request = new ListSnapshotsRequest(); + $response = $gapicClient->listSnapshots($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.dataflow.v1beta3.SnapshotsV1Beta3/ListSnapshots', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listSnapshotsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + $request = new ListSnapshotsRequest(); + try { + $gapicClient->listSnapshots($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteSnapshotAsyncTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new DeleteSnapshotResponse(); + $transport->addResponse($expectedResponse); + $request = new DeleteSnapshotRequest(); + $response = $gapicClient->deleteSnapshotAsync($request)->wait(); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.dataflow.v1beta3.SnapshotsV1Beta3/DeleteSnapshot', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } +} diff --git a/Dataflow/tests/Unit/V1beta3/Client/TemplatesServiceClientTest.php b/Dataflow/tests/Unit/V1beta3/Client/TemplatesServiceClientTest.php new file mode 100644 index 000000000000..ac219e68e8b2 --- /dev/null +++ b/Dataflow/tests/Unit/V1beta3/Client/TemplatesServiceClientTest.php @@ -0,0 +1,290 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return TemplatesServiceClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new TemplatesServiceClient($options); + } + + /** @test */ + public function createJobFromTemplateTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $id = 'id3355'; + $projectId2 = 'projectId2939242356'; + $name = 'name3373707'; + $stepsLocation = 'stepsLocation-354969139'; + $replaceJobId = 'replaceJobId459700424'; + $clientRequestId = 'clientRequestId-1902516801'; + $replacedByJobId = 'replacedByJobId-671370122'; + $location2 = 'location21541837352'; + $createdFromSnapshotId = 'createdFromSnapshotId1520659672'; + $satisfiesPzs = false; + $expectedResponse = new Job(); + $expectedResponse->setId($id); + $expectedResponse->setProjectId($projectId2); + $expectedResponse->setName($name); + $expectedResponse->setStepsLocation($stepsLocation); + $expectedResponse->setReplaceJobId($replaceJobId); + $expectedResponse->setClientRequestId($clientRequestId); + $expectedResponse->setReplacedByJobId($replacedByJobId); + $expectedResponse->setLocation($location2); + $expectedResponse->setCreatedFromSnapshotId($createdFromSnapshotId); + $expectedResponse->setSatisfiesPzs($satisfiesPzs); + $transport->addResponse($expectedResponse); + $request = new CreateJobFromTemplateRequest(); + $response = $gapicClient->createJobFromTemplate($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.dataflow.v1beta3.TemplatesService/CreateJobFromTemplate', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createJobFromTemplateExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + $request = new CreateJobFromTemplateRequest(); + try { + $gapicClient->createJobFromTemplate($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getTemplateTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new GetTemplateResponse(); + $transport->addResponse($expectedResponse); + $request = new GetTemplateRequest(); + $response = $gapicClient->getTemplate($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.dataflow.v1beta3.TemplatesService/GetTemplate', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getTemplateExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + $request = new GetTemplateRequest(); + try { + $gapicClient->getTemplate($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function launchTemplateTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new LaunchTemplateResponse(); + $transport->addResponse($expectedResponse); + $request = new LaunchTemplateRequest(); + $response = $gapicClient->launchTemplate($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.dataflow.v1beta3.TemplatesService/LaunchTemplate', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function launchTemplateExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + $request = new LaunchTemplateRequest(); + try { + $gapicClient->launchTemplate($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createJobFromTemplateAsyncTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $id = 'id3355'; + $projectId2 = 'projectId2939242356'; + $name = 'name3373707'; + $stepsLocation = 'stepsLocation-354969139'; + $replaceJobId = 'replaceJobId459700424'; + $clientRequestId = 'clientRequestId-1902516801'; + $replacedByJobId = 'replacedByJobId-671370122'; + $location2 = 'location21541837352'; + $createdFromSnapshotId = 'createdFromSnapshotId1520659672'; + $satisfiesPzs = false; + $expectedResponse = new Job(); + $expectedResponse->setId($id); + $expectedResponse->setProjectId($projectId2); + $expectedResponse->setName($name); + $expectedResponse->setStepsLocation($stepsLocation); + $expectedResponse->setReplaceJobId($replaceJobId); + $expectedResponse->setClientRequestId($clientRequestId); + $expectedResponse->setReplacedByJobId($replacedByJobId); + $expectedResponse->setLocation($location2); + $expectedResponse->setCreatedFromSnapshotId($createdFromSnapshotId); + $expectedResponse->setSatisfiesPzs($satisfiesPzs); + $transport->addResponse($expectedResponse); + $request = new CreateJobFromTemplateRequest(); + $response = $gapicClient->createJobFromTemplateAsync($request)->wait(); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.dataflow.v1beta3.TemplatesService/CreateJobFromTemplate', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } +}