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 ;
4042import java .util .concurrent .BlockingQueue ;
4143import java .util .concurrent .LinkedBlockingQueue ;
4244import java .util .concurrent .TimeUnit ;
45+ import junit .framework .Assert ;
4346import org .junit .AfterClass ;
4447import org .junit .BeforeClass ;
4548import org .junit .Rule ;
@@ -52,6 +55,9 @@ public class ITPubSubTest {
5255 private static TopicAdminClient topicAdminClient ;
5356 private static SubscriptionAdminClient subscriptionAdminClient ;
5457 private static String projectId ;
58+ private static final boolean IS_VPC_TEST =
59+ System .getenv ("GOOGLE_CLOUD_TESTS_IN_VPCSC" ) != null
60+ && System .getenv ("GOOGLE_CLOUD_TESTS_IN_VPCSC" ).equalsIgnoreCase ("true" );
5561
5662 @ Rule public Timeout globalTimeout = Timeout .seconds (300 );
5763
@@ -107,6 +113,31 @@ public void testTopicPolicy() {
107113 topicAdminClient .deleteTopic (topicName );
108114 }
109115
116+ @ Test
117+ public void testVPCPushSubscriber () throws Exception {
118+ assumeTrue (IS_VPC_TEST );
119+ ProjectTopicName topicName =
120+ ProjectTopicName .of (projectId , formatForTest ("testing-vpc-push-subscriber-topic" ));
121+ ProjectSubscriptionName subscriptionName =
122+ ProjectSubscriptionName .of (
123+ projectId , formatForTest ("testing-vpc-push-subscriber-subscription" ));
124+ topicAdminClient .createTopic (topicName );
125+
126+ try {
127+ subscriptionAdminClient .createSubscription (
128+ subscriptionName ,
129+ topicName ,
130+ PushConfig .newBuilder ().setPushEndpoint ("random_point" ).build (),
131+ 10 );
132+ subscriptionAdminClient .deleteSubscription (subscriptionName );
133+ Assert .fail ("No exception raised" );
134+ } catch (PermissionDeniedException e ) {
135+ // expected
136+ }
137+
138+ topicAdminClient .deleteTopic (topicName );
139+ }
140+
110141 @ Test
111142 public void testPublishSubscribe () throws Exception {
112143 ProjectTopicName topicName =
0 commit comments