diff --git a/tasks/snippets/pom.xml b/tasks/snippets/pom.xml new file mode 100644 index 00000000000..a8bf8633780 --- /dev/null +++ b/tasks/snippets/pom.xml @@ -0,0 +1,60 @@ + + + 4.0.0 + com.google.cloud + cloudtasks-snippets + jar + Google Cloud Tasks Snippets + https://github.com/googleapis/java-tasks + + + + com.google.cloud.samples + shared-configuration + 1.2.0 + + + + 1.8 + 1.8 + UTF-8 + + + + + + + + com.google.cloud + libraries-bom + 26.1.3 + pom + import + + + + + + + com.google.cloud + google-cloud-tasks + + + + + junit + junit + 4.13.2 + test + + + com.google.truth + truth + 1.1.3 + test + + + diff --git a/tasks/snippets/src/main/java/com/example/task/CreateHttpTask.java b/tasks/snippets/src/main/java/com/example/task/CreateHttpTask.java new file mode 100644 index 00000000000..e86636bbc6b --- /dev/null +++ b/tasks/snippets/src/main/java/com/example/task/CreateHttpTask.java @@ -0,0 +1,67 @@ +/* + * Copyright 2018 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.task; + +// [START cloud_tasks_create_http_task] +import com.google.cloud.tasks.v2.CloudTasksClient; +import com.google.cloud.tasks.v2.HttpMethod; +import com.google.cloud.tasks.v2.HttpRequest; +import com.google.cloud.tasks.v2.QueueName; +import com.google.cloud.tasks.v2.Task; +import com.google.protobuf.ByteString; +import java.io.IOException; +import java.nio.charset.Charset; + +public class CreateHttpTask { + + public static void main(String[] args) throws IOException { + // TODO(developer): Replace these variables before running the sample. + String projectId = "my-project-id"; + String locationId = "us-central1"; + String queueId = "my-queue"; + createTask(projectId, locationId, queueId); + } + + // Create a task with a HTTP target using the Cloud Tasks client. + public static void createTask(String projectId, String locationId, String queueId) + throws IOException { + + // Instantiates a client. + try (CloudTasksClient client = CloudTasksClient.create()) { + String url = "https://example.com/taskhandler"; + String payload = "Hello, World!"; + + // Construct the fully qualified queue name. + String queuePath = QueueName.of(projectId, locationId, queueId).toString(); + + // Construct the task body. + Task.Builder taskBuilder = + Task.newBuilder() + .setHttpRequest( + HttpRequest.newBuilder() + .setBody(ByteString.copyFrom(payload, Charset.defaultCharset())) + .setUrl(url) + .setHttpMethod(HttpMethod.POST) + .build()); + + // Send create task request. + Task task = client.createTask(queuePath, taskBuilder.build()); + System.out.println("Task created: " + task.getName()); + } + } +} +// [END cloud_tasks_create_http_task] diff --git a/tasks/snippets/src/main/java/com/example/task/CreateHttpTaskWithToken.java b/tasks/snippets/src/main/java/com/example/task/CreateHttpTaskWithToken.java new file mode 100644 index 00000000000..91cd8c2275d --- /dev/null +++ b/tasks/snippets/src/main/java/com/example/task/CreateHttpTaskWithToken.java @@ -0,0 +1,78 @@ +/* + * Copyright 2019 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.task; + +// [START cloud_tasks_create_http_task_with_token] +import com.google.cloud.tasks.v2.CloudTasksClient; +import com.google.cloud.tasks.v2.HttpMethod; +import com.google.cloud.tasks.v2.HttpRequest; +import com.google.cloud.tasks.v2.OidcToken; +import com.google.cloud.tasks.v2.QueueName; +import com.google.cloud.tasks.v2.Task; +import com.google.protobuf.ByteString; +import java.io.IOException; +import java.nio.charset.Charset; + +public class CreateHttpTaskWithToken { + + public static void main(String[] args) throws IOException { + // TODO(developer): Replace these variables before running the sample. + String projectId = "my-project-id"; + String locationId = "us-central1"; + String queueId = "my-queue"; + String serviceAccountEmail = + "java-docs-samples-testing@java-docs-samples-testing.iam.gserviceaccount.com"; + createTask(projectId, locationId, queueId, serviceAccountEmail); + } + + // Create a task with a HTTP target and authorization token using the Cloud Tasks client. + public static void createTask( + String projectId, String locationId, String queueId, String serviceAccountEmail) + throws IOException { + + // Instantiates a client. + try (CloudTasksClient client = CloudTasksClient.create()) { + String url = + "https://example.com/taskhandler"; // The full url path that the request will be sent to + String payload = "Hello, World!"; // The task HTTP request body + + // Construct the fully qualified queue name. + String queuePath = QueueName.of(projectId, locationId, queueId).toString(); + + // Add your service account email to construct the OIDC token. + // in order to add an authentication header to the request. + OidcToken.Builder oidcTokenBuilder = + OidcToken.newBuilder().setServiceAccountEmail(serviceAccountEmail); + + // Construct the task body. + Task.Builder taskBuilder = + Task.newBuilder() + .setHttpRequest( + HttpRequest.newBuilder() + .setBody(ByteString.copyFrom(payload, Charset.defaultCharset())) + .setHttpMethod(HttpMethod.POST) + .setUrl(url) + .setOidcToken(oidcTokenBuilder) + .build()); + + // Send create task request. + Task task = client.createTask(queuePath, taskBuilder.build()); + System.out.println("Task created: " + task.getName()); + } + } +} +// [END cloud_tasks_create_http_task_with_token] diff --git a/tasks/snippets/src/main/java/com/example/task/CreateQueue.java b/tasks/snippets/src/main/java/com/example/task/CreateQueue.java new file mode 100644 index 00000000000..04aa81101ad --- /dev/null +++ b/tasks/snippets/src/main/java/com/example/task/CreateQueue.java @@ -0,0 +1,54 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.example.task; + +// [START cloud_tasks_create_queue] +import com.google.cloud.tasks.v2.CloudTasksClient; +import com.google.cloud.tasks.v2.LocationName; +import com.google.cloud.tasks.v2.Queue; +import com.google.cloud.tasks.v2.QueueName; +import java.io.IOException; + +public class CreateQueue { + + public static void main(String[] args) throws IOException { + // TODO(developer): Replace these variables before running the sample. + String projectId = "my-project-id"; + String locationId = "us-central1"; + String queueId = "my-queue"; + createQueue(projectId, locationId, queueId); + } + + // Create a queue using the Cloud Tasks client. + public static void createQueue(String projectId, String locationId, String queueId) + throws IOException { + + // Instantiates a client. + try (CloudTasksClient client = CloudTasksClient.create()) { + + // Construct the fully qualified location. + String parent = LocationName.of(projectId, locationId).toString(); + + // Construct the fully qualified queue path. + String queuePath = QueueName.of(projectId, locationId, queueId).toString(); + + // Send create queue request. + Queue queue = client.createQueue(parent, Queue.newBuilder().setName(queuePath).build()); + + System.out.println("Queue created: " + queue.getName()); + } + } +} +// [END cloud_tasks_create_queue] diff --git a/tasks/snippets/src/main/java/com/example/task/DeleteQueue.java b/tasks/snippets/src/main/java/com/example/task/DeleteQueue.java new file mode 100644 index 00000000000..6f5d9898b48 --- /dev/null +++ b/tasks/snippets/src/main/java/com/example/task/DeleteQueue.java @@ -0,0 +1,49 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.example.task; + +// [START cloud_tasks_delete_queue] +import com.google.cloud.tasks.v2.CloudTasksClient; +import com.google.cloud.tasks.v2.QueueName; +import java.io.IOException; + +public class DeleteQueue { + + public static void main(String[] args) throws IOException { + // TODO(developer): Replace these variables before running the sample. + String projectId = "my-project-id"; + String locationId = "us-central1"; + String queueId = "my-queue"; + deleteQueue(projectId, locationId, queueId); + } + + // Delete a queue using the Cloud Tasks client. + public static void deleteQueue(String projectId, String locationId, String queueId) + throws IOException { + + // Instantiates a client. + try (CloudTasksClient client = CloudTasksClient.create()) { + + // Construct the fully qualified queue path. + String queuePath = QueueName.of(projectId, locationId, queueId).toString(); + + // Send delete queue request. + client.deleteQueue(queuePath); + + System.out.println("Queue deleted: " + queueId); + } + } +} +// [END cloud_tasks_delete_queue] diff --git a/tasks/snippets/src/main/java/com/example/task/ListQueues.java b/tasks/snippets/src/main/java/com/example/task/ListQueues.java new file mode 100644 index 00000000000..2405eecacae --- /dev/null +++ b/tasks/snippets/src/main/java/com/example/task/ListQueues.java @@ -0,0 +1,57 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.example.task; + +// [START cloud_tasks_list_queues] +import com.google.cloud.tasks.v2.CloudTasksClient; +import com.google.cloud.tasks.v2.LocationName; +import com.google.cloud.tasks.v2.Queue; +import java.io.IOException; + +public class ListQueues { + + public static void main(String[] args) throws IOException { + // TODO(developer): Replace these variables before running the sample. + String projectId = "my-project-id"; + String locationId = "us-central1"; + listQueues(projectId, locationId); + } + + // List queues using the Cloud Tasks client. + public static void listQueues(String projectId, String locationId) throws IOException { + + // Instantiates a client. + try (CloudTasksClient client = CloudTasksClient.create()) { + + // Construct the fully qualified location path. + String parent = LocationName.of(projectId, locationId).toString(); + + // Send list queues request. + CloudTasksClient.ListQueuesPagedResponse response = client.listQueues(parent); + + // Iterate over results and print queue names + int total = 0; + for (Queue queue : response.iterateAll()) { + System.out.println(queue.getName()); + total++; + } + + if (total == 0) { + System.out.println("No queues found!"); + } + } + } +} +// [END cloud_tasks_list_queues] diff --git a/tasks/snippets/src/test/java/com/example/task/CreateHttpTaskIT.java b/tasks/snippets/src/test/java/com/example/task/CreateHttpTaskIT.java new file mode 100644 index 00000000000..11fd89f0b12 --- /dev/null +++ b/tasks/snippets/src/test/java/com/example/task/CreateHttpTaskIT.java @@ -0,0 +1,87 @@ +/* + * Copyright 2019 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.task; + +import static com.google.common.truth.Truth.assertThat; +import static org.junit.Assert.assertNotNull; + +import com.google.cloud.tasks.v2.CloudTasksClient; +import com.google.cloud.tasks.v2.QueueName; +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** Tests for creating Tasks with HTTP targets. */ +@RunWith(JUnit4.class) +public class CreateHttpTaskIT { + private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); + private static final String LOCATION_ID = System.getenv("LOCATION_ID"); + private static final String QUEUE_ID = "default"; + private static final String EMAIL = + "java-docs-samples-testing@java-docs-samples-testing.iam.gserviceaccount.com"; + private ByteArrayOutputStream bout; + private PrintStream out; + + private static void requireEnvVar(String varName) { + assertNotNull( + String.format("Environment variable '%s' must be set to perform these tests.", varName), + System.getenv(varName)); + } + + @BeforeClass + public static void checkRequirements() { + requireEnvVar("GOOGLE_CLOUD_PROJECT"); + requireEnvVar("LOCATION_ID"); + } + + @Before + public void setUp() { + bout = new ByteArrayOutputStream(); + out = new PrintStream(bout); + System.setOut(out); + } + + @After + public void tearDown() { + System.setOut(null); + try (CloudTasksClient client = CloudTasksClient.create()) { + String queuePath = QueueName.of(PROJECT_ID, LOCATION_ID, QUEUE_ID).toString(); + client.purgeQueue(queuePath); + } catch (Exception e) { + System.out.println("Error with queue purge."); + } + } + + @Test + public void testCreateHttpTask() throws Exception { + CreateHttpTask.createTask(PROJECT_ID, LOCATION_ID, QUEUE_ID); + String got = bout.toString(); + assertThat(got).contains("Task created:"); + } + + @Test + public void testCreateHttpTaskWithToken() throws Exception { + CreateHttpTaskWithToken.createTask(PROJECT_ID, LOCATION_ID, QUEUE_ID, EMAIL); + String got = bout.toString(); + assertThat(got).contains("Task created:"); + } +} diff --git a/tasks/snippets/src/test/java/com/example/task/CreateQueueIT.java b/tasks/snippets/src/test/java/com/example/task/CreateQueueIT.java new file mode 100644 index 00000000000..8677ee30d09 --- /dev/null +++ b/tasks/snippets/src/test/java/com/example/task/CreateQueueIT.java @@ -0,0 +1,78 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.example.task; + +import static com.google.common.truth.Truth.assertThat; +import static org.junit.Assert.assertNotNull; + +import com.google.cloud.tasks.v2.CloudTasksClient; +import com.google.cloud.tasks.v2.QueueName; +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import java.util.UUID; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** Tests for creating queues. */ +@RunWith(JUnit4.class) +public class CreateQueueIT { + private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); + private static final String LOCATION_ID = System.getenv("LOCATION_ID"); + private static final String QUEUE_ID = "test-queue-" + UUID.randomUUID(); + + private ByteArrayOutputStream bout; + private PrintStream out; + + private static void requireEnvVar(String varName) { + assertNotNull( + String.format("Environment variable '%s' must be set to perform these tests.", varName), + System.getenv(varName)); + } + + @BeforeClass + public static void checkRequirements() { + requireEnvVar("GOOGLE_CLOUD_PROJECT"); + requireEnvVar("LOCATION_ID"); + } + + @Before + public void setUp() { + bout = new ByteArrayOutputStream(); + out = new PrintStream(bout); + System.setOut(out); + } + + @After + public void tearDown() { + try (CloudTasksClient client = CloudTasksClient.create()) { + String queuePath = QueueName.of(PROJECT_ID, LOCATION_ID, QUEUE_ID).toString(); + client.deleteQueue(queuePath); + } catch (Exception e) { + System.out.println("Error with queue deletion."); + } + System.setOut(null); + } + + @Test + public void testCreateQueue() throws Exception { + CreateQueue.createQueue(PROJECT_ID, LOCATION_ID, QUEUE_ID); + String got = bout.toString(); + assertThat(got).contains("Queue created:"); + } +} diff --git a/tasks/snippets/src/test/java/com/example/task/DeleteQueueIT.java b/tasks/snippets/src/test/java/com/example/task/DeleteQueueIT.java new file mode 100644 index 00000000000..3bf3ad63a56 --- /dev/null +++ b/tasks/snippets/src/test/java/com/example/task/DeleteQueueIT.java @@ -0,0 +1,92 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.example.task; + +import static com.google.common.truth.Truth.assertThat; +import static org.junit.Assert.assertNotNull; + +import com.google.api.gax.rpc.NotFoundException; +import com.google.cloud.tasks.v2.CloudTasksClient; +import com.google.cloud.tasks.v2.LocationName; +import com.google.cloud.tasks.v2.Queue; +import com.google.cloud.tasks.v2.QueueName; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.util.UUID; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** Tests for deleting queues. */ +@RunWith(JUnit4.class) +public class DeleteQueueIT { + private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); + private static final String LOCATION_ID = System.getenv("LOCATION_ID"); + private static final String QUEUE_ID = "test-queue-" + UUID.randomUUID(); + + private ByteArrayOutputStream bout; + private PrintStream out; + private Queue queue; + + private static void requireEnvVar(String varName) { + assertNotNull( + String.format("Environment variable '%s' must be set to perform these tests.", varName), + System.getenv(varName)); + } + + @BeforeClass + public static void checkRequirements() { + requireEnvVar("GOOGLE_CLOUD_PROJECT"); + requireEnvVar("LOCATION_ID"); + } + + @Before + public void setUp() { + bout = new ByteArrayOutputStream(); + out = new PrintStream(bout); + System.setOut(out); + + try (CloudTasksClient client = CloudTasksClient.create()) { + String parent = LocationName.of(PROJECT_ID, LOCATION_ID).toString(); + String queuePath = QueueName.of(PROJECT_ID, LOCATION_ID, QUEUE_ID).toString(); + queue = client.createQueue(parent, Queue.newBuilder().setName(queuePath).build()); + } catch (Exception e) { + System.out.println("Error with queue creation."); + } + } + + @After + public void tearDown() { + try (CloudTasksClient client = CloudTasksClient.create()) { + client.deleteQueue(queue.getName()); + } catch (IOException e) { + System.out.println("Error with queue deletion."); + } catch (NotFoundException e) { + System.out.println("Queue already successfully deleted"); + } + System.setOut(null); + } + + @Test + public void testDeleteQueue() throws Exception { + DeleteQueue.deleteQueue(PROJECT_ID, LOCATION_ID, QUEUE_ID); + String got = bout.toString(); + assertThat(got).contains("Queue deleted:"); + } +} diff --git a/tasks/snippets/src/test/java/com/example/task/ListQueuesIT.java b/tasks/snippets/src/test/java/com/example/task/ListQueuesIT.java new file mode 100644 index 00000000000..287a83ecb84 --- /dev/null +++ b/tasks/snippets/src/test/java/com/example/task/ListQueuesIT.java @@ -0,0 +1,89 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.example.task; + +import static com.google.common.truth.Truth.assertThat; +import static org.junit.Assert.assertNotNull; + +import com.google.cloud.tasks.v2.CloudTasksClient; +import com.google.cloud.tasks.v2.LocationName; +import com.google.cloud.tasks.v2.Queue; +import com.google.cloud.tasks.v2.QueueName; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.util.UUID; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** Tests for listing queues. */ +@RunWith(JUnit4.class) +public class ListQueuesIT { + private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); + private static final String LOCATION_ID = System.getenv("LOCATION_ID"); + private static final String QUEUE_ID = "test-queue-" + UUID.randomUUID(); + + private ByteArrayOutputStream bout; + private PrintStream out; + private Queue queue; + + private static void requireEnvVar(String varName) { + assertNotNull( + String.format("Environment variable '%s' must be set to perform these tests.", varName), + System.getenv(varName)); + } + + @BeforeClass + public static void checkRequirements() { + requireEnvVar("GOOGLE_CLOUD_PROJECT"); + requireEnvVar("LOCATION_ID"); + } + + @Before + public void setUp() { + bout = new ByteArrayOutputStream(); + out = new PrintStream(bout); + System.setOut(out); + + try (CloudTasksClient client = CloudTasksClient.create()) { + String parent = LocationName.of(PROJECT_ID, LOCATION_ID).toString(); + String queuePath = QueueName.of(PROJECT_ID, LOCATION_ID, QUEUE_ID).toString(); + queue = client.createQueue(parent, Queue.newBuilder().setName(queuePath).build()); + } catch (Exception e) { + System.out.println("Error with queue creation."); + } + } + + @After + public void tearDown() { + try (CloudTasksClient client = CloudTasksClient.create()) { + client.deleteQueue(queue.getName()); + } catch (IOException e) { + System.out.println("Error with queue deletion."); + } + System.setOut(null); + } + + @Test + public void testListQueues() throws Exception { + ListQueues.listQueues(PROJECT_ID, LOCATION_ID); + String got = bout.toString(); + assertThat(got).contains(queue.getName()); + } +}