Search in sources :

Example 31 with TopicName

use of com.google.pubsub.v1.TopicName in project google-cloud-java by GoogleCloudPlatform.

the class TopicAdminClientTest method getTopicTest.

@Test
@SuppressWarnings("all")
public void getTopicTest() {
    TopicName name = TopicName.create("[PROJECT]", "[TOPIC]");
    Topic expectedResponse = Topic.newBuilder().setNameWithTopicName(name).build();
    mockPublisher.addResponse(expectedResponse);
    TopicName topic = TopicName.create("[PROJECT]", "[TOPIC]");
    Topic actualResponse = client.getTopic(topic);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<GeneratedMessageV3> actualRequests = mockPublisher.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    GetTopicRequest actualRequest = (GetTopicRequest) actualRequests.get(0);
    Assert.assertEquals(topic, actualRequest.getTopicAsTopicName());
}
Also used : GetTopicRequest(com.google.pubsub.v1.GetTopicRequest) Topic(com.google.pubsub.v1.Topic) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) TopicName(com.google.pubsub.v1.TopicName) Test(org.junit.Test)

Example 32 with TopicName

use of com.google.pubsub.v1.TopicName in project google-cloud-java by GoogleCloudPlatform.

the class TopicAdminClientTest method createTopicExceptionTest.

@Test
@SuppressWarnings("all")
public void createTopicExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockPublisher.addException(exception);
    try {
        TopicName name = TopicName.create("[PROJECT]", "[TOPIC]");
        client.createTopic(name);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException) TopicName(com.google.pubsub.v1.TopicName) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 33 with TopicName

use of com.google.pubsub.v1.TopicName in project google-cloud-java by GoogleCloudPlatform.

the class TopicAdminClientTest method publishExceptionTest.

@Test
@SuppressWarnings("all")
public void publishExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockPublisher.addException(exception);
    try {
        TopicName topic = TopicName.create("[PROJECT]", "[TOPIC]");
        ByteString data = ByteString.copyFromUtf8("-86");
        PubsubMessage messagesElement = PubsubMessage.newBuilder().setData(data).build();
        List<PubsubMessage> messages = Arrays.asList(messagesElement);
        client.publish(topic, messages);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : ByteString(com.google.protobuf.ByteString) StatusRuntimeException(io.grpc.StatusRuntimeException) PubsubMessage(com.google.pubsub.v1.PubsubMessage) TopicName(com.google.pubsub.v1.TopicName) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 34 with TopicName

use of com.google.pubsub.v1.TopicName in project google-cloud-java by GoogleCloudPlatform.

the class TopicAdminClientTest method deleteTopicTest.

@Test
@SuppressWarnings("all")
public void deleteTopicTest() {
    Empty expectedResponse = Empty.newBuilder().build();
    mockPublisher.addResponse(expectedResponse);
    TopicName topic = TopicName.create("[PROJECT]", "[TOPIC]");
    client.deleteTopic(topic);
    List<GeneratedMessageV3> actualRequests = mockPublisher.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    DeleteTopicRequest actualRequest = (DeleteTopicRequest) actualRequests.get(0);
    Assert.assertEquals(topic, actualRequest.getTopicAsTopicName());
}
Also used : Empty(com.google.protobuf.Empty) DeleteTopicRequest(com.google.pubsub.v1.DeleteTopicRequest) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) TopicName(com.google.pubsub.v1.TopicName) Test(org.junit.Test)

Aggregations

TopicName (com.google.pubsub.v1.TopicName)28 Test (org.junit.Test)20 SubscriptionName (com.google.pubsub.v1.SubscriptionName)9 TopicAdminClient (com.google.cloud.pubsub.spi.v1.TopicAdminClient)7 ByteString (com.google.protobuf.ByteString)7 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)7 ApiException (com.google.api.gax.grpc.ApiException)6 PubsubMessage (com.google.pubsub.v1.PubsubMessage)6 Subscription (com.google.pubsub.v1.Subscription)6 Topic (com.google.pubsub.v1.Topic)6 StatusRuntimeException (io.grpc.StatusRuntimeException)6 Publisher (com.google.cloud.pubsub.spi.v1.Publisher)4 SubscriptionAdminClient (com.google.cloud.pubsub.spi.v1.SubscriptionAdminClient)4 PushConfig (com.google.pubsub.v1.PushConfig)3 AckReplyConsumer (com.google.cloud.pubsub.spi.v1.AckReplyConsumer)2 MessageReceiver (com.google.cloud.pubsub.spi.v1.MessageReceiver)2 ListTopicSubscriptionsPagedResponse (com.google.cloud.pubsub.spi.v1.PagedResponseWrappers.ListTopicSubscriptionsPagedResponse)2 Subscriber (com.google.cloud.pubsub.spi.v1.Subscriber)2 Policy (com.google.iam.v1.Policy)2 DeleteTopicRequest (com.google.pubsub.v1.DeleteTopicRequest)2