use of com.google.pubsub.v1.Subscription in project google-cloud-java by GoogleCloudPlatform.
the class SubscriptionAdminClientTest method deleteSubscriptionTest.
@Test
@SuppressWarnings("all")
public void deleteSubscriptionTest() {
Empty expectedResponse = Empty.newBuilder().build();
mockSubscriber.addResponse(expectedResponse);
SubscriptionName subscription = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]");
client.deleteSubscription(subscription);
List<GeneratedMessageV3> actualRequests = mockSubscriber.getRequests();
Assert.assertEquals(1, actualRequests.size());
DeleteSubscriptionRequest actualRequest = (DeleteSubscriptionRequest) actualRequests.get(0);
Assert.assertEquals(subscription, actualRequest.getSubscriptionAsSubscriptionName());
}
use of com.google.pubsub.v1.Subscription in project google-cloud-java by GoogleCloudPlatform.
the class SubscriptionAdminClientTest method createSubscriptionTest.
@Test
@SuppressWarnings("all")
public void createSubscriptionTest() {
SubscriptionName name2 = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]");
TopicNameOneof topic2 = TopicNameOneof.from(TopicName.create("[PROJECT]", "[TOPIC]"));
int ackDeadlineSeconds2 = -921632575;
boolean retainAckedMessages = false;
Subscription expectedResponse = Subscription.newBuilder().setNameWithSubscriptionName(name2).setTopicWithTopicNameOneof(topic2).setAckDeadlineSeconds(ackDeadlineSeconds2).setRetainAckedMessages(retainAckedMessages).build();
mockSubscriber.addResponse(expectedResponse);
SubscriptionName name = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]");
TopicName topic = TopicName.create("[PROJECT]", "[TOPIC]");
PushConfig pushConfig = PushConfig.newBuilder().build();
int ackDeadlineSeconds = 2135351438;
Subscription actualResponse = client.createSubscription(name, topic, pushConfig, ackDeadlineSeconds);
Assert.assertEquals(expectedResponse, actualResponse);
List<GeneratedMessageV3> actualRequests = mockSubscriber.getRequests();
Assert.assertEquals(1, actualRequests.size());
Subscription actualRequest = (Subscription) actualRequests.get(0);
Assert.assertEquals(name, actualRequest.getNameAsSubscriptionName());
Assert.assertEquals(TopicNameOneof.from(topic), actualRequest.getTopicAsTopicNameOneof());
Assert.assertEquals(pushConfig, actualRequest.getPushConfig());
Assert.assertEquals(ackDeadlineSeconds, actualRequest.getAckDeadlineSeconds());
}
use of com.google.pubsub.v1.Subscription in project google-cloud-java by GoogleCloudPlatform.
the class SubscriptionAdminClientTest method modifyAckDeadlineTest.
@Test
@SuppressWarnings("all")
public void modifyAckDeadlineTest() {
Empty expectedResponse = Empty.newBuilder().build();
mockSubscriber.addResponse(expectedResponse);
SubscriptionName subscription = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]");
List<String> ackIds = new ArrayList<>();
int ackDeadlineSeconds = 2135351438;
client.modifyAckDeadline(subscription, ackIds, ackDeadlineSeconds);
List<GeneratedMessageV3> actualRequests = mockSubscriber.getRequests();
Assert.assertEquals(1, actualRequests.size());
ModifyAckDeadlineRequest actualRequest = (ModifyAckDeadlineRequest) actualRequests.get(0);
Assert.assertEquals(subscription, actualRequest.getSubscriptionAsSubscriptionName());
Assert.assertEquals(ackIds, actualRequest.getAckIdsList());
Assert.assertEquals(ackDeadlineSeconds, actualRequest.getAckDeadlineSeconds());
}
use of com.google.pubsub.v1.Subscription in project google-cloud-java by GoogleCloudPlatform.
the class SubscriptionAdminClientTest method acknowledgeExceptionTest.
@Test
@SuppressWarnings("all")
public void acknowledgeExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockSubscriber.addException(exception);
try {
SubscriptionName subscription = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]");
List<String> ackIds = new ArrayList<>();
client.acknowledge(subscription, ackIds);
Assert.fail("No exception raised");
} catch (ApiException e) {
Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
}
}
use of com.google.pubsub.v1.Subscription in project google-cloud-java by GoogleCloudPlatform.
the class SubscriptionAdminClientTest method listSubscriptionsTest.
@Test
@SuppressWarnings("all")
public void listSubscriptionsTest() {
String nextPageToken = "";
Subscription subscriptionsElement = Subscription.newBuilder().build();
List<Subscription> subscriptions = Arrays.asList(subscriptionsElement);
ListSubscriptionsResponse expectedResponse = ListSubscriptionsResponse.newBuilder().setNextPageToken(nextPageToken).addAllSubscriptions(subscriptions).build();
mockSubscriber.addResponse(expectedResponse);
ProjectName project = ProjectName.create("[PROJECT]");
ListSubscriptionsPagedResponse pagedListResponse = client.listSubscriptions(project);
List<Subscription> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getSubscriptionsList().get(0), resources.get(0));
List<GeneratedMessageV3> actualRequests = mockSubscriber.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListSubscriptionsRequest actualRequest = (ListSubscriptionsRequest) actualRequests.get(0);
Assert.assertEquals(project, actualRequest.getProjectAsProjectName());
}
Aggregations