1717package com .google .cloud .pubsub .it ;
1818
1919import static com .google .common .truth .Truth .assertThat ;
20+ import static org .junit .Assume .assumeTrue ;
2021
22+ import com .google .api .gax .rpc .PermissionDeniedException ;
2123import com .google .auto .value .AutoValue ;
2224import com .google .cloud .ServiceOptions ;
2325import com .google .cloud .pubsub .v1 .AckReplyConsumer ;
3436import com .google .pubsub .v1 .ProjectTopicName ;
3537import com .google .pubsub .v1 .PubsubMessage ;
3638import com .google .pubsub .v1 .PushConfig ;
39+ import io .grpc .Status ;
40+ import junit .framework .Assert ;
3741import java .util .Collections ;
3842import java .util .List ;
3943import java .util .UUID ;
@@ -52,6 +56,9 @@ public class ITPubSubTest {
5256 private static TopicAdminClient topicAdminClient ;
5357 private static SubscriptionAdminClient subscriptionAdminClient ;
5458 private static String projectId ;
59+ private static final boolean IS_VPC_TEST =
60+ System .getenv ("GOOGLE_CLOUD_TESTS_IN_VPCSC" ) != null
61+ && System .getenv ("GOOGLE_CLOUD_TESTS_IN_VPCSC" ).equalsIgnoreCase ("true" );
5562
5663 @ Rule public Timeout globalTimeout = Timeout .seconds (300 );
5764
@@ -107,6 +114,28 @@ public void testTopicPolicy() {
107114 topicAdminClient .deleteTopic (topicName );
108115 }
109116
117+ @ Test
118+ public void testVPCPushSubscriber () throws Exception {
119+ assumeTrue (IS_VPC_TEST );
120+ ProjectTopicName topicName =
121+ ProjectTopicName .of (projectId , formatForTest ("testing-vpc-push-subscriber-topic" ));
122+ ProjectSubscriptionName subscriptionName =
123+ ProjectSubscriptionName .of (
124+ projectId , formatForTest ("testing-vpc-push-subscriber-subscription" ));
125+ topicAdminClient .createTopic (topicName );
126+
127+ try {
128+ subscriptionAdminClient .createSubscription (
129+ subscriptionName , topicName , PushConfig .newBuilder ().setPushEndpoint ("random_point" ).build (), 10 );
130+ subscriptionAdminClient .deleteSubscription (subscriptionName );
131+ Assert .fail ("No exception raised" );
132+ } catch (PermissionDeniedException e ) {
133+ // expected
134+ }
135+
136+ topicAdminClient .deleteTopic (topicName );
137+ }
138+
110139 @ Test
111140 public void testPublishSubscribe () throws Exception {
112141 ProjectTopicName topicName =
0 commit comments