@Test @SuppressWarnings("all") public void createTopicTest() { ProjectTopicName name2 = ProjectTopicName.of("[PROJECT]", "[TOPIC]"); Topic expectedResponse = Topic.newBuilder().setName(name2.toString()).build(); mockPublisher.addResponse(expectedResponse); ProjectTopicName name = ProjectTopicName.of("[PROJECT]", "[TOPIC]"); Topic actualResponse = client.createTopic(name); Assert.assertEquals(expectedResponse, actualResponse); List<GeneratedMessageV3> actualRequests = mockPublisher.getRequests(); Assert.assertEquals(1, actualRequests.size()); Topic actualRequest = (Topic) actualRequests.get(0); Assert.assertEquals(name, ProjectTopicName.parse(actualRequest.getName())); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern())); }
@Test @SuppressWarnings("all") public void getTopicTest() { ProjectTopicName name = ProjectTopicName.of("[PROJECT]", "[TOPIC]"); Topic expectedResponse = Topic.newBuilder().setName(name.toString()).build(); mockPublisher.addResponse(expectedResponse); ProjectTopicName topic = ProjectTopicName.of("[PROJECT]", "[TOPIC]"); Topic actualResponse = client.getTopic(topic); Assert.assertEquals(expectedResponse, actualResponse); List<GeneratedMessageV3> actualRequests = mockPublisher.getRequests(); Assert.assertEquals(1, actualRequests.size()); GetTopicRequest actualRequest = (GetTopicRequest) actualRequests.get(0); Assert.assertEquals(topic, ProjectTopicName.parse(actualRequest.getTopic())); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern())); }
@Override public void createTopic(TopicPath topic) throws IOException { Topic request = Topic.newBuilder().setName(topic.getPath()).build(); publisherStub().createTopic(request); // ignore Topic result. }
/** * Creates the given topic with the given name. See the <a * href="https://cloud.google.com/pubsub/docs/admin#resource_names"> resource name * rules</a>. * * <p>Sample code: * * <pre><code> * try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) { * ProjectTopicName name = ProjectTopicName.of("[PROJECT]", "[TOPIC]"); * Topic response = topicAdminClient.createTopic(name); * } * </code></pre> * * @param name The name of the topic. It must have the format * `"projects/{project}/topics/{topic}"`. `{topic}` must start with a letter, and contain only * letters (`[A-Za-z]`), numbers (`[0-9]`), dashes (`-`), underscores (`_`), periods (`.`), * tildes (`~`), plus (`+`) or percent signs (`%`). It must be between 3 and 255 characters in * length, and it must not start with `"goog"`. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final Topic createTopic(ProjectTopicName name) { Topic request = Topic.newBuilder().setName(name == null ? null : name.toString()).build(); return createTopic(request); }
/** * Creates the given topic with the given name. See the <a * href="https://cloud.google.com/pubsub/docs/admin#resource_names"> resource name * rules</a>. * * <p>Sample code: * * <pre><code> * try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) { * ProjectTopicName name = ProjectTopicName.of("[PROJECT]", "[TOPIC]"); * Topic response = topicAdminClient.createTopic(name.toString()); * } * </code></pre> * * @param name The name of the topic. It must have the format * `"projects/{project}/topics/{topic}"`. `{topic}` must start with a letter, and contain only * letters (`[A-Za-z]`), numbers (`[0-9]`), dashes (`-`), underscores (`_`), periods (`.`), * tildes (`~`), plus (`+`) or percent signs (`%`). It must be between 3 and 255 characters in * length, and it must not start with `"goog"`. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final Topic createTopic(String name) { Topic request = Topic.newBuilder().setName(name).build(); return createTopic(request); }