Search in sources :

Example 6 with Snapshot

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

the class SubscriptionAdminClientTest method listSnapshotsTest.

@Test
@SuppressWarnings("all")
public void listSnapshotsTest() {
    String nextPageToken = "";
    Snapshot snapshotsElement = Snapshot.newBuilder().build();
    List<Snapshot> snapshots = Arrays.asList(snapshotsElement);
    ListSnapshotsResponse expectedResponse = ListSnapshotsResponse.newBuilder().setNextPageToken(nextPageToken).addAllSnapshots(snapshots).build();
    mockSubscriber.addResponse(expectedResponse);
    ProjectName project = ProjectName.create("[PROJECT]");
    ListSnapshotsPagedResponse pagedListResponse = client.listSnapshots(project);
    List<Snapshot> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getSnapshotsList().get(0), resources.get(0));
    List<GeneratedMessageV3> actualRequests = mockSubscriber.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListSnapshotsRequest actualRequest = (ListSnapshotsRequest) actualRequests.get(0);
    Assert.assertEquals(project, actualRequest.getProjectAsProjectName());
}
Also used : Snapshot(com.google.pubsub.v1.Snapshot) ListSnapshotsRequest(com.google.pubsub.v1.ListSnapshotsRequest) ListSnapshotsResponse(com.google.pubsub.v1.ListSnapshotsResponse) ListSnapshotsPagedResponse(com.google.cloud.pubsub.spi.v1.PagedResponseWrappers.ListSnapshotsPagedResponse) ProjectName(com.google.pubsub.v1.ProjectName) ByteString(com.google.protobuf.ByteString) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)5 SnapshotName (com.google.pubsub.v1.SnapshotName)4 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)3 ApiException (com.google.api.gax.grpc.ApiException)2 DeleteSnapshotRequest (com.google.pubsub.v1.DeleteSnapshotRequest)2 Snapshot (com.google.pubsub.v1.Snapshot)2 SubscriptionName (com.google.pubsub.v1.SubscriptionName)2 StatusRuntimeException (io.grpc.StatusRuntimeException)2 ListSnapshotsPagedResponse (com.google.cloud.pubsub.spi.v1.PagedResponseWrappers.ListSnapshotsPagedResponse)1 ByteString (com.google.protobuf.ByteString)1 Empty (com.google.protobuf.Empty)1 CreateSnapshotRequest (com.google.pubsub.v1.CreateSnapshotRequest)1 ListSnapshotsRequest (com.google.pubsub.v1.ListSnapshotsRequest)1 ListSnapshotsResponse (com.google.pubsub.v1.ListSnapshotsResponse)1 ProjectName (com.google.pubsub.v1.ProjectName)1 TopicName (com.google.pubsub.v1.TopicName)1