/** * * * <pre> * The resulting topics. * </pre> * * <code>repeated .google.pubsub.v1.Topic topics = 1;</code> */ public Builder addTopics(int index, com.google.pubsub.v1.Topic.Builder builderForValue) { if (topicsBuilder_ == null) { ensureTopicsIsMutable(); topics_.add(index, builderForValue.build()); onChanged(); } else { topicsBuilder_.addMessage(index, builderForValue.build()); } return this; } /**
/** * * * <pre> * The resulting topics. * </pre> * * <code>repeated .google.pubsub.v1.Topic topics = 1;</code> */ public Builder addTopics(com.google.pubsub.v1.Topic.Builder builderForValue) { if (topicsBuilder_ == null) { ensureTopicsIsMutable(); topics_.add(builderForValue.build()); onChanged(); } else { topicsBuilder_.addMessage(builderForValue.build()); } return this; } /**
/** * * * <pre> * The resulting topics. * </pre> * * <code>repeated .google.pubsub.v1.Topic topics = 1;</code> */ public Builder setTopics(int index, com.google.pubsub.v1.Topic.Builder builderForValue) { if (topicsBuilder_ == null) { ensureTopicsIsMutable(); topics_.set(index, builderForValue.build()); onChanged(); } else { topicsBuilder_.setMessage(index, builderForValue.build()); } return this; } /**
/** * * * <pre> * The resulting topics. * </pre> * * <code>repeated .google.pubsub.v1.Topic topics = 1;</code> */ public Builder addTopics(int index, com.google.pubsub.v1.Topic.Builder builderForValue) { if (topicsBuilder_ == null) { ensureTopicsIsMutable(); topics_.add(index, builderForValue.build()); onChanged(); } else { topicsBuilder_.addMessage(index, builderForValue.build()); } return this; } /**
/** * * * <pre> * The resulting topics. * </pre> * * <code>repeated .google.pubsub.v1.Topic topics = 1;</code> */ public Builder setTopics(int index, com.google.pubsub.v1.Topic.Builder builderForValue) { if (topicsBuilder_ == null) { ensureTopicsIsMutable(); topics_.set(index, builderForValue.build()); onChanged(); } else { topicsBuilder_.setMessage(index, builderForValue.build()); } return this; } /**
/** * <code>repeated .google.pubsub.v1.Topic topics = 1;</code> * * <pre> * The resulting topics. * </pre> */ public Builder addTopics( int index, com.google.pubsub.v1.Topic.Builder builderForValue) { if (topicsBuilder_ == null) { ensureTopicsIsMutable(); topics_.add(index, builderForValue.build()); onChanged(); } else { topicsBuilder_.addMessage(index, builderForValue.build()); } return this; } /**
/** * <pre> * The resulting topics. * </pre> * * <code>repeated .google.pubsub.v1.Topic topics = 1;</code> */ public Builder setTopics( int index, com.google.pubsub.v1.Topic.Builder builderForValue) { if (topicsBuilder_ == null) { ensureTopicsIsMutable(); topics_.set(index, builderForValue.build()); onChanged(); } else { topicsBuilder_.setMessage(index, builderForValue.build()); } return this; } /**
/** * * * <pre> * The resulting topics. * </pre> * * <code>repeated .google.pubsub.v1.Topic topics = 1;</code> */ public Builder addTopics(com.google.pubsub.v1.Topic.Builder builderForValue) { if (topicsBuilder_ == null) { ensureTopicsIsMutable(); topics_.add(builderForValue.build()); onChanged(); } else { topicsBuilder_.addMessage(builderForValue.build()); } return this; } /**
/** * <code>repeated .google.pubsub.v1.Topic topics = 1;</code> * * <pre> * The resulting topics. * </pre> */ public Builder addTopics( com.google.pubsub.v1.Topic.Builder builderForValue) { if (topicsBuilder_ == null) { ensureTopicsIsMutable(); topics_.add(builderForValue.build()); onChanged(); } else { topicsBuilder_.addMessage(builderForValue.build()); } return this; } /**
/** * <code>repeated .google.pubsub.v1.Topic topics = 1;</code> * * <pre> * The resulting topics. * </pre> */ public Builder setTopics( int index, com.google.pubsub.v1.Topic.Builder builderForValue) { if (topicsBuilder_ == null) { ensureTopicsIsMutable(); topics_.set(index, builderForValue.build()); onChanged(); } else { topicsBuilder_.setMessage(index, builderForValue.build()); } return this; } /**
/** * <pre> * The resulting topics. * </pre> * * <code>repeated .google.pubsub.v1.Topic topics = 1;</code> */ public Builder addTopics( int index, com.google.pubsub.v1.Topic.Builder builderForValue) { if (topicsBuilder_ == null) { ensureTopicsIsMutable(); topics_.add(index, builderForValue.build()); onChanged(); } else { topicsBuilder_.addMessage(index, builderForValue.build()); } return this; } /**
/** * <pre> * The resulting topics. * </pre> * * <code>repeated .google.pubsub.v1.Topic topics = 1;</code> */ public Builder addTopics( com.google.pubsub.v1.Topic.Builder builderForValue) { if (topicsBuilder_ == null) { ensureTopicsIsMutable(); topics_.add(builderForValue.build()); onChanged(); } else { topicsBuilder_.addMessage(builderForValue.build()); } return this; } /**
/** * * * <pre> * The updated topic object. * </pre> * * <code>.google.pubsub.v1.Topic topic = 1;</code> */ public Builder setTopic(com.google.pubsub.v1.Topic.Builder builderForValue) { if (topicBuilder_ == null) { topic_ = builderForValue.build(); onChanged(); } else { topicBuilder_.setMessage(builderForValue.build()); } return this; } /**
@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); }
@Test @SuppressWarnings("all") public void listTopicsTest() { String nextPageToken = ""; Topic topicsElement = Topic.newBuilder().build(); List<Topic> topics = Arrays.asList(topicsElement); ListTopicsResponse expectedResponse = ListTopicsResponse.newBuilder() .setNextPageToken(nextPageToken) .addAllTopics(topics) .build(); mockPublisher.addResponse(expectedResponse); ProjectName project = ProjectName.of("[PROJECT]"); ListTopicsPagedResponse pagedListResponse = client.listTopics(project); List<Topic> resources = Lists.newArrayList(pagedListResponse.iterateAll()); Assert.assertEquals(1, resources.size()); Assert.assertEquals(expectedResponse.getTopicsList().get(0), resources.get(0)); List<GeneratedMessageV3> actualRequests = mockPublisher.getRequests(); Assert.assertEquals(1, actualRequests.size()); ListTopicsRequest actualRequest = (ListTopicsRequest) actualRequests.get(0); Assert.assertEquals(project, ProjectName.parse(actualRequest.getProject())); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern())); }
/** * 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); }
@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())); }
/** * * * <pre> * The updated topic object. * </pre> * * <code>.google.pubsub.v1.Topic topic = 1;</code> */ public Builder setTopic(com.google.pubsub.v1.Topic.Builder builderForValue) { if (topicBuilder_ == null) { topic_ = builderForValue.build(); onChanged(); } else { topicBuilder_.setMessage(builderForValue.build()); } return this; } /**
@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())); }