diff --git a/google-cloud-storage/pom.xml b/google-cloud-storage/pom.xml
index 7d8c8f99c7..e4282ce48c 100644
--- a/google-cloud-storage/pom.xml
+++ b/google-cloud-storage/pom.xml
@@ -80,14 +80,6 @@
com.google.protobuf
protobuf-java-util
-
- com.google.cloud
- google-cloud-pubsub
-
-
- com.google.api.grpc
- proto-google-cloud-pubsub-v1
-
org.threeten
threetenbp
@@ -159,6 +151,11 @@
truth
test
+
+ com.google.cloud
+ google-cloud-pubsub
+ test
+
org.easymock
easymock
diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/NotificationInfo.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/NotificationInfo.java
index 74c6e6ba2f..34c2d326d6 100644
--- a/google-cloud-storage/src/main/java/com/google/cloud/storage/NotificationInfo.java
+++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/NotificationInfo.java
@@ -17,12 +17,12 @@
import static com.google.common.base.Preconditions.checkNotNull;
+import com.google.api.pathtemplate.PathTemplate;
import com.google.api.services.storage.model.Notification;
import com.google.common.base.Function;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
-import com.google.pubsub.v1.ProjectTopicName;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
@@ -37,6 +37,8 @@
public class NotificationInfo implements Serializable {
private static final long serialVersionUID = 5725883368559753810L;
+ private static final PathTemplate PATH_TEMPLATE =
+ PathTemplate.createWithoutUrlEncoding("projects/{project}/topics/{topic}");
public enum PayloadFormat {
JSON_API_V1,
@@ -58,7 +60,7 @@ public Notification apply(NotificationInfo NotificationInfo) {
}
};
private final String generatedId;
- private final ProjectTopicName topic;
+ private final String topic;
private final List eventTypes;
private final Map customAttributes;
private final PayloadFormat payloadFormat;
@@ -69,7 +71,7 @@ public Notification apply(NotificationInfo NotificationInfo) {
public static final class Builder {
private String generatedId;
- private ProjectTopicName topic;
+ private String topic;
private List eventTypes;
private Map customAttributes;
private PayloadFormat payloadFormat;
@@ -77,7 +79,7 @@ public static final class Builder {
private String etag;
private String selfLink;
- Builder(ProjectTopicName topic) {
+ Builder(String topic) {
this.topic = topic;
}
@@ -102,7 +104,8 @@ Builder setSelfLink(String selfLink) {
return this;
}
- public Builder setTopic(ProjectTopicName topic) {
+ /** The name of the topic. It must have the format "projects/{project}/topics/{topic}". */
+ public Builder setTopic(String topic) {
this.topic = topic;
return this;
}
@@ -155,8 +158,8 @@ public String getGeneratedId() {
return generatedId;
}
- /** Returns the Cloud PubSub topic to which this subscription publishes. */
- public ProjectTopicName getTopic() {
+ /** Returns the topic to which this subscription publishes. */
+ public String getTopic() {
return topic;
}
@@ -248,25 +251,35 @@ Notification toPb() {
notificationPb.setPayloadFormat(PayloadFormat.NONE.toString());
}
notificationPb.setSelfLink(selfLink);
- notificationPb.setTopic(topic.toString());
+ notificationPb.setTopic(topic);
return notificationPb;
}
- /** Creates a {@code NotificationInfo} object for the provided topic name. */
- public static NotificationInfo of(ProjectTopicName topic) {
+ /**
+ * Creates a {@code NotificationInfo} object for the provided topic name.
+ *
+ * @param topic The name of the topic. It must have the format
+ * "projects/{project}/topics/{topic}".
+ */
+ public static NotificationInfo of(String topic) {
+ PATH_TEMPLATE.validatedMatch(topic, "topic name must be in valid format");
return newBuilder(topic).build();
}
/**
* Returns a {@code NotificationInfo} builder where the topic's name is set to the provided name.
+ *
+ * @param topic The name of the topic. It must have the format
+ * "projects/{project}/topics/{topic}".
*/
- public static Builder newBuilder(ProjectTopicName topic) {
+ public static Builder newBuilder(String topic) {
+ PATH_TEMPLATE.validatedMatch(topic, "topic name must be in valid format");
return new Builder(topic);
}
static NotificationInfo fromPb(Notification notificationPb) {
- Builder builder = newBuilder(ProjectTopicName.parse(notificationPb.getTopic()));
+ Builder builder = newBuilder(notificationPb.getTopic());
if (notificationPb.getId() != null) {
builder.setGeneratedId(notificationPb.getId());
}
@@ -283,7 +296,7 @@ static NotificationInfo fromPb(Notification notificationPb) {
builder.setObjectNamePrefix(notificationPb.getObjectNamePrefix());
}
if (notificationPb.getTopic() != null) {
- builder.setTopic(ProjectTopicName.parse(notificationPb.getTopic()));
+ builder.setTopic(notificationPb.getTopic());
}
if (notificationPb.getEventTypes() != null) {
builder.setEventTypes(notificationPb.getEventTypes());
diff --git a/google-cloud-storage/src/test/java/com/google/cloud/storage/NotificationInfoTest.java b/google-cloud-storage/src/test/java/com/google/cloud/storage/NotificationInfoTest.java
index 88d5ce68b6..40b8a5ccf1 100644
--- a/google-cloud-storage/src/test/java/com/google/cloud/storage/NotificationInfoTest.java
+++ b/google-cloud-storage/src/test/java/com/google/cloud/storage/NotificationInfoTest.java
@@ -21,7 +21,6 @@
import com.google.cloud.storage.NotificationInfo.PayloadFormat;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
-import com.google.pubsub.v1.ProjectTopicName;
import java.util.List;
import java.util.Map;
import org.junit.Test;
@@ -35,7 +34,7 @@ public class NotificationInfoTest {
ImmutableList.of("OBJECT_FINALIZE", "OBJECT_METADATA_UPDATE");
private static final String OBJECT_NAME_PREFIX = "index.html";
private static final PayloadFormat PAYLOAD_FORMAT = PayloadFormat.JSON_API_V1.JSON_API_V1;
- private static final ProjectTopicName TOPIC = ProjectTopicName.of("myProject", "topic1");
+ private static final String TOPIC = "projects/myProject/topics/topic1";
private static final Map CUSTOM_ATTRIBUTES = ImmutableMap.of("label1", "value1");
private static final NotificationInfo NOTIFICATION_INFO =
NotificationInfo.newBuilder(TOPIC)
diff --git a/google-cloud-storage/src/test/java/com/google/cloud/storage/StorageImplTest.java b/google-cloud-storage/src/test/java/com/google/cloud/storage/StorageImplTest.java
index 21930a9cd2..b470ed39c1 100644
--- a/google-cloud-storage/src/test/java/com/google/cloud/storage/StorageImplTest.java
+++ b/google-cloud-storage/src/test/java/com/google/cloud/storage/StorageImplTest.java
@@ -58,7 +58,6 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.common.io.BaseEncoding;
-import com.google.pubsub.v1.ProjectTopicName;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
@@ -385,7 +384,7 @@ public long millisTime() {
private static final String OBJECT_NAME_PREFIX = "index.html";
private static final NotificationInfo.PayloadFormat PAYLOAD_FORMAT =
NotificationInfo.PayloadFormat.JSON_API_V1.JSON_API_V1;
- private static final ProjectTopicName TOPIC = ProjectTopicName.of("myProject", "topic1");
+ private static final String TOPIC = "projects/myProject/topics/topic1";
private static final Map CUSTOM_ATTRIBUTES = ImmutableMap.of("label1", "value1");
private static final NotificationInfo NOTIFICATION_INFO_01 =
NotificationInfo.newBuilder(TOPIC)
diff --git a/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITStorageTest.java b/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITStorageTest.java
index a42636ddd8..c3ff603837 100644
--- a/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITStorageTest.java
+++ b/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITStorageTest.java
@@ -93,7 +93,6 @@
import com.google.iam.v1.Binding;
import com.google.iam.v1.IAMPolicyGrpc;
import com.google.iam.v1.SetIamPolicyRequest;
-import com.google.pubsub.v1.ProjectTopicName;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import io.grpc.Metadata;
@@ -183,8 +182,9 @@ public class ITStorageTest {
private static final String ID = UUID.randomUUID().toString().substring(0, 8);
private static final NotificationInfo.PayloadFormat PAYLOAD_FORMAT =
NotificationInfo.PayloadFormat.JSON_API_V1.JSON_API_V1;
- private static final ProjectTopicName TOPIC =
- ProjectTopicName.of(PROJECT, String.format("test_topic_foo_%s", ID));
+
+ private static final String TOPIC =
+ String.format("projects/%s/topics/test_topic_foo_%s", PROJECT, ID);
private static final Map CUSTOM_ATTRIBUTES = ImmutableMap.of("label1", "value1");
@BeforeClass
@@ -208,11 +208,10 @@ public static void beforeClass() throws IOException {
// Create pubsub topic for notification.
topicAdminClient = TopicAdminClient.create();
topicAdminClient.createTopic(TOPIC);
- com.google.iam.v1.Policy policy = topicAdminClient.getIamPolicy(TOPIC.toString());
+ com.google.iam.v1.Policy policy = topicAdminClient.getIamPolicy(TOPIC);
Binding binding =
Binding.newBuilder().setRole("roles/owner").addMembers("allAuthenticatedUsers").build();
- topicAdminClient.setIamPolicy(
- TOPIC.toString(), policy.toBuilder().addBindings(binding).build());
+ topicAdminClient.setIamPolicy(TOPIC, policy.toBuilder().addBindings(binding).build());
// Create a notification on a bucket.
NotificationInfo notificationInfo =
@@ -3254,7 +3253,7 @@ public void testGetNotification() {
Notification actualNotification = storage.getNotification(BUCKET, notification.getId());
assertEquals(CUSTOM_ATTRIBUTES, actualNotification.getCustomAttributes());
assertEquals(PAYLOAD_FORMAT.name(), actualNotification.getPayloadFormat());
- assertTrue(actualNotification.getTopic().contains(TOPIC.toString()));
+ assertTrue(actualNotification.getTopic().contains(TOPIC));
}
@Test
@@ -3264,7 +3263,7 @@ public void testListNotification() {
if (actualNotification.getId().equals(notification.getId())) {
assertEquals(CUSTOM_ATTRIBUTES, actualNotification.getCustomAttributes());
assertEquals(PAYLOAD_FORMAT.name(), actualNotification.getPayloadFormat());
- assertTrue(actualNotification.getTopic().contains(TOPIC.toString()));
+ assertTrue(actualNotification.getTopic().contains(TOPIC));
}
}
}
diff --git a/pom.xml b/pom.xml
index 4a815cf59c..e061e7fb7c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -151,16 +151,6 @@
proto-google-common-protos
1.17.0
-
- com.google.cloud
- google-cloud-pubsub
- 1.102.1
-
-
- com.google.api.grpc
- proto-google-cloud-pubsub-v1
- 1.84.1
-
org.threeten
threetenbp
@@ -194,6 +184,12 @@
1.0.1
test
+
+ com.google.cloud
+ google-cloud-pubsub
+ 1.102.1
+ test
+
org.easymock
easymock