@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())); }
subBuilder.mergeFrom(topic_); topic_ = subBuilder.buildPartial();
@java.lang.Override public com.google.pubsub.v1.Topic buildPartial() { com.google.pubsub.v1.Topic result = new com.google.pubsub.v1.Topic(this); int from_bitField0_ = bitField0_; int to_bitField0_ = 0; result.name_ = name_; result.labels_ = internalGetLabels(); result.labels_.makeImmutable(); if (messageStoragePolicyBuilder_ == null) { result.messageStoragePolicy_ = messageStoragePolicy_; } else { result.messageStoragePolicy_ = messageStoragePolicyBuilder_.build(); } result.bitField0_ = to_bitField0_; onBuilt(); return result; }
subBuilder.mergeFrom(topic_); topic_ = subBuilder.buildPartial();
messageStoragePolicy_ = value; onChanged(); } else { messageStoragePolicyBuilder_.mergeFrom(value);
/** * * * <pre> * Policy constraining how messages published to the topic may be stored. It * is determined when the topic is created based on the policy configured at * the project level. It must not be set by the caller in the request to * CreateTopic or to UpdateTopic. This field will be populated in the * responses for GetTopic, CreateTopic, and UpdateTopic: if not present in the * response, then no constraints are in effect. * </pre> * * <code>.google.pubsub.v1.MessageStoragePolicy message_storage_policy = 3;</code> */ public Builder setMessageStoragePolicy(com.google.pubsub.v1.MessageStoragePolicy value) { if (messageStoragePolicyBuilder_ == null) { if (value == null) { throw new NullPointerException(); } messageStoragePolicy_ = value; onChanged(); } else { messageStoragePolicyBuilder_.setMessage(value); } return this; } /**
/** * * * <pre> * Policy constraining how messages published to the topic may be stored. It * is determined when the topic is created based on the policy configured at * the project level. It must not be set by the caller in the request to * CreateTopic or to UpdateTopic. This field will be populated in the * responses for GetTopic, CreateTopic, and UpdateTopic: if not present in the * response, then no constraints are in effect. * </pre> * * <code>.google.pubsub.v1.MessageStoragePolicy message_storage_policy = 3;</code> */ public Builder setMessageStoragePolicy( com.google.pubsub.v1.MessageStoragePolicy.Builder builderForValue) { if (messageStoragePolicyBuilder_ == null) { messageStoragePolicy_ = builderForValue.build(); onChanged(); } else { messageStoragePolicyBuilder_.setMessage(builderForValue.build()); } return this; } /**
/** * * * <pre> * 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"`. * </pre> * * <code>string name = 1;</code> */ public Builder setNameBytes(com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } checkByteStringIsUtf8(value); name_ = value; onChanged(); return this; }
/** * * * <pre> * Policy constraining how messages published to the topic may be stored. It * is determined when the topic is created based on the policy configured at * the project level. It must not be set by the caller in the request to * CreateTopic or to UpdateTopic. This field will be populated in the * responses for GetTopic, CreateTopic, and UpdateTopic: if not present in the * response, then no constraints are in effect. * </pre> * * <code>.google.pubsub.v1.MessageStoragePolicy message_storage_policy = 3;</code> */ public Builder clearMessageStoragePolicy() { if (messageStoragePolicyBuilder_ == null) { messageStoragePolicy_ = null; onChanged(); } else { messageStoragePolicy_ = null; messageStoragePolicyBuilder_ = null; } return this; } /**
/** * <code>optional string name = 1;</code> * * <pre> * 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"`. * </pre> */ public Builder setName( java.lang.String value) { if (value == null) { throw new NullPointerException(); } name_ = value; onChanged(); return this; } /**
/** * * * <pre> * The updated topic object. * </pre> * * <code>.google.pubsub.v1.Topic topic = 1;</code> */ public Builder mergeTopic(com.google.pubsub.v1.Topic value) { if (topicBuilder_ == null) { if (topic_ != null) { topic_ = com.google.pubsub.v1.Topic.newBuilder(topic_).mergeFrom(value).buildPartial(); } else { topic_ = value; } onChanged(); } else { topicBuilder_.mergeFrom(value); } return this; } /**
/** * <code>optional string name = 1;</code> * * <pre> * 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"`. * </pre> */ public Builder setNameBytes( com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } checkByteStringIsUtf8(value); name_ = value; onChanged(); return this; } public final Builder setUnknownFields(
/** * <pre> * 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"`. * </pre> * * <code>optional string name = 1;</code> */ public Builder setNameBytes( com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } checkByteStringIsUtf8(value); name_ = value; onChanged(); return this; } public final Builder setUnknownFields(
/** * * * <pre> * 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"`. * </pre> * * <code>string name = 1;</code> */ public Builder setName(java.lang.String value) { if (value == null) { throw new NullPointerException(); } name_ = value; onChanged(); return this; } /**
/** * <pre> * 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"`. * </pre> * * <code>optional string name = 1;</code> */ public Builder setName( java.lang.String value) { if (value == null) { throw new NullPointerException(); } name_ = value; onChanged(); 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; } /**
/** * * * <pre> * 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"`. * </pre> * * <code>string name = 1;</code> */ public Builder clearName() { name_ = getDefaultInstance().getName(); onChanged(); 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; } /**